Posted By

itutavac on 11/12/12


Tagged

lista polje zaglavlje operacije funkcije


Versions (?)

lista_polje.h


 / Published in: C++
 

Implementacije liste pomoću polja

  1. #ifndef _LISTA_POLJE_H_
  2. #define _LISTA_POLJE_H_
  3.  
  4. struct _tempList
  5. {
  6. int sifra;
  7. std::string naziv,vrsta,datum;
  8. float cijena;
  9. };
  10.  
  11. struct _list
  12. {
  13. _tempList a[50];
  14. int next;
  15. };
  16.  
  17. typedef int List;
  18. typedef _list Array;
  19.  
  20. int FirstL(_list *list)
  21. {
  22. return 0;
  23. }
  24.  
  25. int EndL(_list *list)
  26. {
  27. return list->next;
  28. }
  29.  
  30. int NextL(int temp,_list *list)
  31. {
  32. if (temp == EndL(list))
  33. return 0;
  34. return temp+1;
  35. }
  36.  
  37. int PreviousL(int temp,_list *list)
  38. {
  39. if (temp == FirstL(list))
  40. return 0;
  41. return temp-1;
  42. }
  43.  
  44. int LocateL(int temp,_list *list)
  45. {
  46. for (int i =0;i<EndL(list);i++)
  47. {
  48. if (list->a[i].sifra == temp)
  49. return i;
  50. }
  51. return EndL(list);
  52. }
  53.  
  54. int LocateL(float temp,_list *list)
  55. {
  56. for (int i = 0;i<EndL(list);i++)
  57. {
  58. if (list->a[i].cijena == temp)
  59. return i;
  60. }
  61. return EndL(list);
  62. }
  63.  
  64. int LocateL(std::string temp,_list *list)
  65. {
  66. for (int i = 0;i<EndL(list);i++)
  67. {
  68. if (list->a[i].datum == temp || list->a[i].naziv == temp|| list->a[i].vrsta == temp)
  69. return i;
  70. }
  71. }
  72.  
  73. bool InsertL(_tempList copyElement,int index,_list *list)
  74. {
  75. if (list->next == 0)
  76. list->a[index] = copyElement;
  77. else
  78. {
  79. for (int i = EndL(list); i > index; i--)
  80. list->a[i] = list->a[i-1];
  81. list->a[index] = copyElement;
  82. }
  83. list->next++;
  84. return true;
  85. }
  86.  
  87. bool DeleteL(int index,_list *list)
  88. { //index preko locate
  89. for (int i = index; i<EndL(list);i++)
  90. list->a[i] = list->a[i+1];
  91. list->next--;
  92. return true;
  93. }
  94.  
  95. bool DeleteAllL(_list *list)
  96. {
  97. list->next = 0;
  98. return true;
  99. }
  100.  
  101. _tempList RetrieveL(int index,_list *list)
  102. {
  103. return list->a[index];
  104. }
  105.  
  106. bool InitL(_list *list)
  107. {
  108. list->next = 0;
  109. return true;
  110. }
  111.  
  112.  
  113. #endif

Report this snippet  

You need to login to post a comment.