lista_pokazivac.h


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

Lista implementirana pomoću pokazivača.


Copy this code and paste it in your HTML
  1. #include <string>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. struct zivotinje{
  7. int sifra;
  8. char vrsta[50];
  9. char naziv[50];
  10. int cijena;
  11. string datum;
  12. };
  13.  
  14.  
  15.  
  16.  
  17. struct tlista {
  18. zivotinje c;
  19. tlista *next;
  20. };
  21.  
  22. tlista *l=new tlista;
  23. typedef tlista *tip;
  24.  
  25.  
  26. tlista *FirstL (tlista *l) {
  27. return l->next;
  28. }
  29.  
  30. tlista *EndL (tlista *l) {
  31. tlista *zadnji=l;
  32. while (zadnji->next!=NULL) zadnji=zadnji->next;
  33. return zadnji->next;
  34. }
  35. tlista *NextL (tlista *p, tlista *l) {
  36. return p->next;
  37. }
  38. tlista *PreviousL (tlista *p, tlista *l) {
  39. tlista *temp=l;
  40. while (temp->next!=p) {
  41. temp=temp->next;
  42. }
  43. return temp;
  44. }
  45. tlista *LocateL (zivotinje a, tlista *l) {
  46. tlista *temp=l->next;
  47. while (temp) {
  48. if (a.sifra==temp->c.sifra) return temp;
  49. temp=temp->next;
  50. }
  51. return EndL(l);
  52. }
  53. void InsertL (zivotinje x, tlista *p, tlista *l) {
  54. tlista *novi=new tlista;
  55. p=PreviousL(p, l);
  56. novi->c=x;
  57. novi->next=p->next;
  58. p->next=novi;
  59. }
  60. void DeleteL (tlista *p, tlista *l) {
  61. p=PreviousL(p, l);
  62. tlista *temp=p->next;
  63. p->next=temp->next;
  64. delete temp;
  65. }
  66. zivotinje RetrieveL (tlista *p, tlista *l) {
  67. return p->c;
  68. }
  69.  
  70.  
  71. void *DeleteAllL (tlista *l) {
  72. while (l->next) {
  73. tlista *temp=l->next;
  74. l->next=temp->next;
  75. delete temp;
  76. }
  77. delete l;
  78. }
  79. void *InitL (tlista *l) {
  80. l->next=NULL;
  81. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.