Posted By


tsteyska on 11/12/12

Tagged


Statistics


Viewed 466 times
Favorited by 0 user(s)

Z1_lista_polja.h


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

Implementacija liste pomocu polja


Copy this code and paste it in your HTML
  1. struct podaci{
  2. int sifra,datum,cijena;
  3. char naziv[20],vrsta[20];
  4. };
  5. struct lista{
  6. podaci pod[1000];
  7. int k;
  8. };
  9.  
  10. typedef int tlistap;
  11.  
  12. int EndL(lista *L)
  13. {
  14. return L->k;
  15. }
  16.  
  17. int FirstL(lista *L)
  18. {
  19. if (L->k==0)
  20. return EndL(L);
  21. else
  22. return 0;
  23. }
  24.  
  25. int NextL(int p, lista *L)
  26. {
  27. if(p == (L->k)-1)
  28. return EndL(L);
  29. else
  30. return p+1;
  31. }
  32.  
  33. int PreviousL(int p, lista *L)
  34. {
  35. if (p>0)
  36. return p-1;
  37. else
  38. return 0;
  39. }
  40.  
  41. int LocateL(podaci x, lista *L)
  42. {
  43. for (int i=0; i < L->k; i++)
  44. if(x.sifra == (L->pod[i].sifra))
  45. return i;
  46.  
  47. return EndL(L);
  48. }
  49.  
  50. int InsertL(podaci x, int p, lista *L)
  51. {
  52. if (p<0 || p > L->k)
  53. return 0;
  54. int pokazivac=L->k;
  55. for(int i=pokazivac-1; i>=p; i--)
  56. {
  57. L->pod[i+1] = L->pod[i];
  58. }
  59. L->pod[p]=x;
  60. L->k++;
  61. return 1;
  62. }
  63.  
  64. int DeleteL(int p, lista *L)
  65. {
  66. if (p<0 || p>=L->k)
  67. return 0;
  68. for(int i=p; i< L->k; i++)
  69. L->pod[i] = L->pod[i+1];
  70. L->k--;
  71. return 1;
  72. }
  73.  
  74. podaci RetrieveL(int p, lista *L)
  75. {
  76. return L->pod[p];
  77. }
  78.  
  79. void DeleteAllL(lista *L)
  80. {
  81. L->k=0;
  82. }
  83.  
  84. lista *InitL(lista *L)
  85. {
  86. L = new lista;
  87. for (int i=0; i<1000; i++)
  88. {
  89. L->pod[i].sifra=0;
  90. L->pod[i].datum=0;
  91. }
  92. L->k=0;
  93. return L;
  94. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.