Posted By


jaksas on 11/12/12

Tagged


Statistics


Viewed 26 times
Favorited by 0 user(s)

lista_pokazivača.h


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

impementacija liste pomoću pokazivača


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.