Posted By

nikola9999 on 10/24/10


Tagged

pokazivac


Versions (?)

liste_pokazivaci


 / Published in: C++
 

  1. #include <iostream>
  2. using namespace std;
  3. struct tpacijent{
  4. int maticni;
  5. char ime_prez[40];
  6. int godine;
  7. };
  8. tpacijent*pacijent=new tpacijent;
  9. tpacijent*pacijent_mladi=new tpacijent;
  10. tpacijent*pacijent_novi=new tpacijent;
  11. typedef int element;
  12. typedef int elementtype;
  13. struct lis {
  14. tpacijent value;
  15. list *next;
  16. };
  17.  
  18. typedef lis list;
  19. typedef lis *element;
  20.  
  21. element FirstL(list *L) {
  22. return L;
  23. }
  24.  
  25. element EndL(list *L) {
  26. list *pok;
  27. pok = L;
  28.  
  29. while (pok->next)
  30. pok = pok->next;
  31.  
  32. return pok;
  33. }
  34.  
  35. element NextL(list *current, list *L) {
  36. if (current->next != NULL) {
  37. list *pok;
  38. pok = current->next;
  39. return pok;
  40. } else {
  41. cout << "Ne postoji sljedeci element!" << endl;
  42. return NULL;
  43. }
  44. }
  45.  
  46. element PreviousL(list *current, list *L) {
  47. list *pok = L;
  48.  
  49. while ((pok->next != NULL) && (pok->next != current))
  50. pok = pok->next;
  51.  
  52. if (pok != NULL)
  53. return pok;
  54. else {
  55. cout << "Ne postoji prethodni element!" << endl;
  56. return NULL;
  57. }
  58. }
  59.  
  60.  
  61. element LocateL(elementtype val, list *L) {
  62. list *pok;
  63. pok = L->next;
  64.  
  65. while ((pok != NULL) && (pok->value != val))
  66. pok = pok->next;
  67.  
  68. if (pok == NULL)
  69. cout << "Ne postoji trazeni element" << endl;
  70.  
  71. return pok;
  72. }
  73.  
  74.  
  75. void InsertL(elementtype val, list *p) {
  76. list *pok;
  77. pok = p->next;
  78.  
  79. list *novi = new list;
  80. novi->value = val;
  81. p->next = novi;
  82.  
  83. if (pok != NULL)
  84. novi->next = pok;
  85. else
  86. novi->next = NULL;
  87. }
  88.  
  89.  
  90. void DeleteL(list *p, list *L) {
  91. list *pok;
  92. if (p->next != NULL) {
  93. pok = p;
  94. pok->next = p->next->next;
  95. delete p->next;
  96. } else {
  97. cout << "Element ne postoji u listi!" << endl;
  98. }
  99. }
  100.  
  101.  
  102. elementtype RetrieveL(list *p, list *L) {
  103. if (p != NULL)
  104. return p->next->value;
  105. else {
  106. cout << "Ne postoji trazeni element" << endl;
  107. return 0;
  108. }
  109. }
  110.  
  111.  
  112. void DeleteAllL(list *L) {
  113. list *prev, *curr;
  114. prev = L;
  115. curr = L->next;
  116.  
  117. while (curr) {
  118. delete prev;
  119. prev = curr;
  120. curr = curr->next;
  121. }
  122.  
  123. delete prev;
  124. L = NULL;
  125. }
  126.  
  127. void InitL(list *L) {
  128. L->next = NULL;
  129. }

Report this snippet  

You need to login to post a comment.