Biblioteka lista_pokazivaci.h


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

U ovoj biblioteci su definirane funkcije za operacije nad listom, ali se, za razliku od prethodne biblioteke, ovdje koriste pokazivači kojima se implementira tzv. vezana lista.


Copy this code and paste it in your HTML
  1. struct List {
  2. zivotinja value;
  3. List* next;
  4. };
  5.  
  6. typedef List Lista;
  7. typedef List* element;
  8.  
  9.  
  10. element FirstL(Lista *L) {
  11. return L;
  12. }
  13.  
  14.  
  15. element EndL(Lista *L) {
  16. while(L->next != NULL) {
  17. L = L->next;
  18. }
  19. return L;
  20. }
  21.  
  22. element NextL(element P, Lista *L) {
  23. return P->next;
  24. }
  25.  
  26. element PreviousL(element P, Lista *L) {
  27. while(L->next != P) {
  28. L = L->next;
  29. }
  30. return L;
  31. }
  32.  
  33. element LocateL(zivotinja X, Lista *L) {
  34. while (L->next->value.sifra != X.sifra) {
  35. L = L->next;
  36. }
  37. return L;
  38. }
  39.  
  40.  
  41. bool InsertL(zivotinja X, element P, Lista *L) {
  42. element n = new Lista;
  43. n->value = X;
  44. n->next = P->next;
  45. P->next = n;
  46. return true;
  47. }
  48.  
  49. void DeleteL(element P, Lista *L) {
  50. element del = P->next;
  51. P->next = del->next;
  52. delete del;
  53. }
  54.  
  55.  
  56. zivotinja RetrieveL(element P, Lista *L) {
  57. return P->next->value;
  58. }
  59.  
  60. void DeleteAll(Lista *L){
  61. element del = L->next;
  62. while (del != NULL) {
  63. L->next = del->next;
  64. delete del;
  65. del = L->next;
  66. }
  67. }
  68.  
  69. void InitL(Lista *L) {
  70. L->next = NULL;
  71. }

Report this snippet


Comments


You need to login to view comments.