Posted By


ihranj on 11/12/12

Tagged


Statistics


Viewed 35 times
Favorited by 0 user(s)

hranj_lista_polje


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

funkcija zaglavlja koju ćemo koristiti u main programu


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.