Posted By


bart1990 on 11/01/10

Tagged


Statistics


Viewed 580 times
Favorited by 0 user(s)

lista_pokazivaci.h


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



Copy this code and paste it in your HTML
  1. //Implementacije liste pomocu pokazivaca
  2.  
  3. struct osoba{
  4. char ime[50];
  5. int god;
  6. int mat;
  7. };
  8.  
  9. osoba pacijent;
  10.  
  11. struct lista {
  12. int mat,god;
  13. char ime[50];
  14. lista *next;
  15. };
  16.  
  17. typedef struct lista* element;
  18.  
  19. element EndL(lista *l){
  20. lista *p=l;
  21. while (p)
  22. p=p->next;
  23. return p;
  24. }
  25.  
  26. element FirstL(lista *l){
  27. if(l->next==NULL) return EndL(l);
  28. return l->next;
  29. }
  30.  
  31.  
  32. element NextL(element e, lista *l){
  33. return e->next;
  34. }
  35.  
  36.  
  37. element PreviousL(element e, lista *l){
  38. lista *p=l->next;
  39. if(e==l->next){
  40. exit(0);
  41. }
  42. while(e!=p->next && p->next!=NULL)
  43. p=p->next;
  44. return p;
  45. }
  46.  
  47. element LocateL(osoba x, lista *l){
  48. lista *p=l->next;
  49. while(p!=NULL&p->mat!=x.mat)
  50. p=p->next;
  51. return p;
  52. }
  53.  
  54.  
  55. bool InsertL(osoba x, element e, lista *l){
  56.  
  57. lista *p=l, *n=new lista;
  58. while(p->next!=e)
  59. p=p->next;
  60. n->mat=x.mat;
  61. n->god=x.god;
  62. strcpy(n->ime,x.ime);
  63. n->next=e;
  64. p->next=n;
  65. return 1;
  66.  
  67. }
  68.  
  69. bool DeleteL(element e, lista *l){
  70. lista *p=l;
  71. while(p->next!=e)
  72. p=p->next;
  73. p->next=e->next;
  74. delete e;
  75. return 1;
  76. }
  77.  
  78.  
  79. osoba RetrieveL(element e, lista *l){
  80. pacijent.mat = e->mat;
  81. pacijent.god = e->god;
  82. strcpy(pacijent.ime,e->ime);
  83. return pacijent;
  84. }
  85.  
  86. void DeleteAllL(lista *l){
  87. element p;
  88. while (l->next != NULL) {
  89. p=l->next;
  90. l->next = l->next->next;
  91. delete p;
  92. }
  93. }
  94.  
  95.  
  96. lista* InitL(lista *l){
  97. l = new lista;
  98. l->next = NULL;
  99. return l;
  100. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.