Posted By

mstarjac on 11/12/12


Tagged


Versions (?)

polje.h


 / Published in: C++
 

Biblioteka polje

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct podaci{
  5. int sifra;
  6. char naziv[40], vrsta[40];
  7. float cijena;
  8. short dan,mj,godina;
  9. };
  10.  
  11. struct animal{
  12. podaci zivotinja[1000];
  13. int sljedeci;
  14. };
  15.  
  16. int var(){
  17. return 1;
  18. }
  19. typedef int element;
  20.  
  21. element EndL(animal *list){
  22. return list->sljedeci;
  23. };
  24.  
  25. element FirstL(animal *list){
  26. if(!list->zivotinja) return EndL(list);//-----------------------
  27. else return 0;
  28. };
  29.  
  30. element NextL(element p,animal *list){
  31. if(p==EndL(list)){
  32. cout<<"Pogreska : Ne postoji element nakon trazenog elementa";
  33. return 0;
  34. }
  35. else if(p==EndL(list)-1) return EndL(list);
  36. else return p+1;
  37. };//NexT END
  38.  
  39. element PreviousL(element p,animal *list){
  40. if(p==FirstL(list)){
  41. cout<<"Pogreska: Ne postoji element prije trazenog elementa";
  42. return 0;
  43. }
  44. else if(p==EndL(list)) return EndL(list)-1;
  45. else return p-1;
  46. };//PreviousL END
  47.  
  48. element LocateL(element x, animal *list){
  49. for(int i=0;i<list->sljedeci;i++)
  50. if( (list->zivotinja[i].sifra)==x) return i;//-----------------------
  51. cout<<"LocateL: U listi ne postoji trazena vrijednost!"<<endl;
  52. return EndL(list);
  53. };//LocateL END
  54.  
  55.  
  56. element LocateL(element x,char trazi[42], animal *list){
  57. for(int i=0;i<list->sljedeci;i++)
  58. if( !strcmp(list->zivotinja[i].naziv,trazi) || !strcmp(list->zivotinja[i].vrsta,trazi)) return i;
  59. cout<<"LocateL: U listi ne postoji trazena vrijednost!"<<endl;
  60. return EndL(list);
  61. };//LocateL END
  62.  
  63. void InsertL(podaci x, element p, animal *list)
  64. {
  65. if(list->sljedeci!=0)
  66. {
  67. for(element i=EndL(list);i>p;i--)
  68. {
  69. list->zivotinja[i]=list->zivotinja[i-1];//-----------------------
  70. }
  71. list->zivotinja[p]=x;//-----------------------
  72. }
  73. else
  74. {
  75. list->zivotinja[p]=x;//-----------------------
  76. }
  77. list->sljedeci+=1;
  78. };// InsterL END
  79.  
  80.  
  81. void DeleteL(element p, animal *list)
  82. {
  83. for(element i=p;i<EndL(list);i++)
  84. {
  85. list->zivotinja[i]=list->zivotinja[i+1];//-----------------------
  86. }
  87. list->sljedeci-=1;
  88. };
  89.  
  90. podaci RetrieveL(element x, animal *list)
  91. {
  92. return list->zivotinja[x];//-----------------------
  93. };
  94.  
  95. void DeleteAllL(animal *list)
  96. {
  97. list->sljedeci=0;
  98. };
  99.  
  100. animal *InitL(animal *list)
  101. {
  102. list->sljedeci=0;
  103. };

Report this snippet  

You need to login to post a comment.