Posted By


msestak2 on 11/10/12

Tagged


Statistics


Viewed 598 times
Favorited by 0 user(s)

Lista_pokazivaci.h


/ Published in: C++
Save to your folder(s)

U ovoj biblioteci su definirane funkcije za izvršavanje operacija nad ATP listom: iniciranje prazne liste(InitL), funkcije koje vraćaju pozicije prvog i zadnjeg elementa(FirstL i EndL), funkcija za umetanje elementa(InsertL), funkcija koja vraća vrijednost elementa na nekoj poziciji(RetrieveL) te funkcije za brisanje pojedinog elementa(DeleteL) ili cijele liste(DeleteAllL).


Copy this code and paste it in your HTML
  1. struct elementtype{
  2. int sifra;
  3. char naziv[30];
  4. char vrsta[30];
  5. float cijena;
  6. struct{
  7. int dan, mjesec, godina;
  8. }datum_dostave;
  9. };
  10.  
  11. struct lis {
  12. elementtype value;
  13. lis *next;
  14. };
  15.  
  16. typedef lis *element;
  17. typedef lis list;
  18.  
  19. void DeleteAllL(list* L){
  20. while(L->next){
  21. element toDelete = L->next;
  22. if(L->next){
  23. L->next = toDelete->next;
  24. delete toDelete;
  25. }
  26. }
  27. delete L;
  28. L = NULL;
  29. }
  30.  
  31.  
  32. list* InitL(list* L){
  33. if(L!=NULL)
  34. DeleteAllL(L);
  35. else{
  36. list *newList = new list;
  37. newList->next = NULL;
  38. return newList;
  39. }
  40. return NULL;
  41. }
  42.  
  43. element FirstL(list* L){
  44. return L;
  45. }
  46.  
  47. element EndL(list* L){
  48. element current = L;
  49. while(current->next){
  50. current = current->next;
  51. }
  52. return current;
  53. }
  54.  
  55. element NextL(element p, list *L){
  56. if(p!=NULL){
  57. if(p==EndL(L)){
  58. return NULL;
  59. }
  60. return p->next;
  61. }
  62. return EndL(L);
  63. }
  64.  
  65. element PreviousL(element p, list *L){
  66. element current = L;
  67. while(current){
  68. if(current->next == p )
  69. return current;
  70. current = current->next;
  71. }
  72. return NULL;
  73. }
  74.  
  75. element LocateL(elementtype el, list* L){
  76. element current = L;
  77. while(current->next){
  78. if(current->next->value.sifra == el.sifra)
  79. return current;
  80. current = current->next;
  81. }
  82. return NULL;
  83. }
  84.  
  85. void InsertL(elementtype el, element p, list* L){
  86. if(p==NULL)
  87. return;
  88. else{
  89. element novi = new lis;
  90. novi->value = el;
  91. novi->next = p->next;
  92. p->next = novi;
  93. }
  94. }
  95.  
  96. void DeleteL(element p, list* L){
  97. element toDelete = p->next;
  98. if(toDelete){
  99. p->next = toDelete->next;
  100. delete toDelete;
  101. }
  102. }
  103.  
  104. elementtype RetrieveL(element p, list* L){
  105. return p->next->value;
  106. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.