/ Published in: C++
Source code biblioteke lista_polja.h gdje je implementiran ATP lista pomoću polja
Expand |
Embed | Plain Text
struct elem{ int sifra; char vrsta[35], naziv[35],datum[12]; float cijena; }; struct lista{ elem detalji[10000]; int cursor; }; typedef int element; lista *InitL(lista *x){ x=new lista; x->cursor=0; return x; } element EndL(lista *x){ return x->cursor; } element FirstL(lista *x){ if(x->cursor==0) return EndL(x); else return 0; } element PreviousL(element e, lista *x){ if(e<=FirstL(x)) return 0; else return e-1; } element NextL(element e, lista *x){ if(e==x->cursor) return x->cursor; return e+1; } elem RetreiveL(element e,lista *x){ return x->detalji[e]; } int InsertL(elem e, element p, lista *x){ int i=EndL(x); while(i>p) x->detalji[i]=x->detalji[--i]; x->detalji[p]=e; x->cursor++; if(e.sifra==x->detalji[p].sifra) return 1; else return 0; } element LocateL(elem e, lista *x){ if(e.sifra==-1){ for(int i=0;i<EndL(x);i++) if(strcmp(e.naziv,x->detalji[i].naziv)==0) return i; } else if(e.sifra==-2){ for(int i=0;i<EndL(x);i++) if(strcmp(e.vrsta,x->detalji[i].vrsta)==0) return i; }return EndL(x); } int DeleteL(element e, lista *x){ if(e==EndL(x)) return 0; for(int i=e;i<EndL(x);i++) x->detalji[i]=x->detalji[i+1]; x->cursor--; return 1; } void DeleteAll(lista *x){ x->cursor=0; }
Comments
Subscribe to comments
You need to login to post a comment.

Datum je implementiran na drugačiji način nego u mojemo kodu, no funkcije su izvedene jednostavno i efikasno.