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