lista_pokazivac.h


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

ovo je lista pomocu pokazivaca potrebna za izvrsavanje koda u glavnom programu


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct ljubimac
  6. {
  7. int kod;
  8. char vrsta[50];
  9. char naziv[50];
  10. int cijena;
  11. int d;
  12. int m;
  13. int g;
  14. };
  15. struct lis
  16. {
  17. ljubimac values;
  18. lis *next;
  19. };
  20. lis *list = new lis;
  21. typedef lis *element;
  22. lis *EndL(lis *list)
  23. {
  24. lis *zadnji = list;
  25. while(zadnji->next)
  26. zadnji = zadnji->next;
  27. return zadnji->next;
  28. }
  29. lis *FirstL(lis *list)
  30. {
  31. if(list == NULL)
  32. return EndL(list);
  33. else
  34. return list->next;
  35. }
  36. lis *NextL(lis *p, lis *list)
  37. {
  38. lis *zadnji = list;
  39. while(zadnji->next)
  40. zadnji = zadnji->next;
  41. if(p == zadnji)
  42. return EndL(list);
  43. if(p == EndL(list))
  44. cout << "Funkcija je nedefinirana!" << endl;
  45. else
  46. return p->next;
  47. }
  48. lis *PreviousL(lis *p, lis *list)
  49. {
  50. lis *prethodni = list;
  51. while(prethodni->next != p)
  52. prethodni = prethodni->next;
  53. return prethodni;
  54. }
  55. lis *LocateL(char x[], lis *list)
  56. {
  57. lis *tekuci = list->next;
  58. while(tekuci)
  59. {
  60. if((strncmp(x,tekuci->values.naziv,sizeof(x))==0) || (strncmp(x,tekuci->values.vrsta,sizeof(x))==0))
  61. return tekuci;
  62. tekuci = tekuci->next;
  63. }
  64. return EndL(list);
  65. }
  66. void InsertL(ljubimac x, lis *p, lis *list)
  67. {
  68. lis *novi = new lis;
  69. p = PreviousL(p, list);
  70. novi->values = x;
  71. novi->next = p->next;
  72. p->next = novi;
  73. }
  74. void DeleteL(lis *p, lis *list)
  75. {
  76. p = PreviousL(p, list);
  77. lis *tekuci = p->next;
  78. p->next = tekuci->next;
  79. delete tekuci;
  80. }
  81. ljubimac RetreiveL(lis *p, lis *list)
  82. {
  83. return p->values;
  84. }
  85. void DeleteAllL(lis *list)
  86. {
  87. lis* brisi = list->next;
  88. while(brisi)
  89. {
  90. list->next = brisi->next;
  91. delete brisi;
  92. brisi = list->next;
  93. }
  94. }
  95. void InitL(lis *list)
  96. {
  97. list->next= NULL;
  98. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.