Posted By


ivadobrincic1 on 11/12/12

Tagged


Statistics


Viewed 845 times
Favorited by 1 user(s)

Lista_pokazivaci.h


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

Implementacija liste pomocu pokazivaca


Copy this code and paste it in your HTML
  1. #include <string>
  2. using namespace std;
  3.  
  4. struct animal {
  5. int sifra;
  6. string naziv;
  7. string vrsta;
  8. string datum;
  9. int cijena;
  10. };
  11.  
  12. struct List {
  13. animal a;
  14. List *next;
  15. };
  16.  
  17. typedef List Lista;
  18. typedef List* element;
  19.  
  20. element GRESKA;
  21.  
  22. void InitL(Lista *list) {
  23. element novi = new Lista;
  24. novi->next = NULL;
  25. list->next = novi;
  26. }
  27.  
  28. element FirstL(Lista *list) {
  29. return list->next;
  30. }
  31.  
  32. element EndL(Lista *list) {
  33. element tekuci = list->next;
  34. while (tekuci->next != NULL) {
  35. tekuci = tekuci->next;
  36. }
  37. return tekuci;
  38. }
  39.  
  40. element PreviousL(element e, Lista *list) {
  41. element tekuci = list;
  42.  
  43. while (tekuci->next != e) {
  44. tekuci = tekuci->next;
  45. }
  46. return tekuci;
  47. }
  48.  
  49. int InsertL(animal nova_z, element e, Lista *list) {
  50. element novi = new Lista;
  51. novi->a = nova_z;
  52.  
  53. novi->next = e;
  54. element prethodni = PreviousL(e, list);
  55. prethodni->next = novi;
  56. return 1;
  57. }
  58.  
  59. bool DeleteL(element e, Lista *list) {
  60.  
  61. element tekuci = list;
  62.  
  63. while (tekuci->next != e) {
  64. tekuci = tekuci->next;
  65. }
  66.  
  67. tekuci->next = e->next;
  68.  
  69. delete e;
  70.  
  71. return true;
  72.  
  73. }
  74.  
  75. void DeleteAll(Lista *list) {
  76. element tekuci, brisi;
  77.  
  78. tekuci = list->next;
  79.  
  80. while(tekuci != NULL) {
  81. brisi = tekuci;
  82. tekuci = tekuci->next;
  83. delete brisi;
  84. }
  85.  
  86. element zadnji = new Lista;
  87. zadnji->next = NULL;
  88. list->next = zadnji;
  89. }
  90.  
  91. element LocateL(animal odbjegla, Lista *list) {
  92. element tekuci;
  93. tekuci = list->next;
  94.  
  95. while (tekuci != EndL(list)) {
  96. if (tekuci->a.sifra == odbjegla.sifra) {
  97. return tekuci;
  98. }
  99. tekuci = tekuci->next;
  100. }
  101.  
  102. return GRESKA;
  103.  
  104. }
  105.  
  106. element NextL(element e, Lista *list) {
  107. return e->next;
  108. }
  109.  
  110. animal RetrieveL (element e, Lista *list) {
  111. return e->a;
  112. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.