/ Published in: C++
funkcija zaglavlja koju ćemo koristiti u main programu
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> #include <string.h> using namespace std; struct tzivotinje{ int sifra; char vrsta[51]; char naziv[51]; int cijena; float datum; int godina; }; struct tlista{ tzivotinje zivotinje[101]; int cursor; }; typedef int element; element FirstL(tlista *l){ return 0; } element EndL(tlista *l){ return l->cursor; } element PreviousL(element p, tlista *l){ if(p==FirstL(l)) return -1; return p-1; } element NextL(element p, tlista *l){ if(p==PreviousL(EndL(l),l)) return EndL(l); return p+1; } element LocateL(tzivotinje z, tlista *l) { int j; for(j=0;j<EndL(l);j++) { if(z.naziv != 0) { if(strcmp(z.naziv,l->zivotinje[j].naziv)==0) return j; } if(z.vrsta != 0) { if(strcmp(z.vrsta, l->zivotinje[j].vrsta)==0) return j; } } return EndL(l); } element InsertL(tzivotinje z, element p, tlista *l){ int j; for(j=EndL(l);j>p;j--) l->zivotinje[j]=l->zivotinje[j-1]; l->zivotinje[p]=z; l->cursor=l->cursor+1; if(l->zivotinje[p].sifra==z.sifra) return 1; else return 0; } element DeleteL(element p, tlista *l){ int j; int pom=l->cursor; for(j=p;j<EndL(l);j++) l->zivotinje[j]=l->zivotinje[j+1]; if(p!=EndL(l)) l->cursor=l->cursor-1; if(pom!=l->cursor) return 1; else return 0; } tzivotinje RetrieveL(element p, tlista *l){ return l->zivotinje[p]; } element DeleteAllL(tlista *l){ l->cursor=0; return 1; } tlista* InitL(tlista *l){ l = new tlista; l->cursor=0; return l; }