/ Published in: C++
Implementacija liste pomocu pokazivaca sadrzi funkcije poput: FirstL(L), EndL(L),NextL(p,L),PreviousL(p,L), LocateL(x,L), InsertL(x,p,L), DeleteL(p,L), RetreiveL(p,L), DeleteAllL(L) i InitL(L)
Expand |
Embed | Plain Text
#include <iostream> using namespace std; #define LISTA_POLJE_H struct zivotinje { int sifra; char vrsta[30],naziv[30]; float cijena; int datum; }; struct lista{ zivotinje elem[1000]; int kursor; }; typedef struct lista l; typedef int element; int EndL(lista *l) { return ((*l).kursor); } int FirstL (lista *l) { if ((*l).kursor==0) return EndL(l); else return (0); } element NextL (element p , lista *l) { if (p==(*l).kursor) cout<<"Funkcija je nedefinirana"<<endl; else return (p+1); } element PreviousL(element p , lista *l) { if(p==0) cout<<"Funkcija je nedefinirana"<<endl; else return (p-1); } element LocateL(zivotinje x, lista *l) { if((*l).kursor==0) { cout<<"Lista je prazna"<<endl; exit(0); } else { int i; i=0; while(i!=(*l).kursor) { if(strcmp(x.naziv, (*l).elem[i].naziv)==0) return i; i++; } } } element Locatel(zivotinje x, lista *l) { if((*l).kursor==0) { cout<<"Lista je prazna"<<endl; exit(0); } else { int i; i=0; while(i!=(*l).kursor) { if(strcmp(x.vrsta, (*l).elem[i].vrsta)==0) return i; i++; } } } element InsertL (zivotinje x, int p , lista *l) { for(int i=EndL(l); i>p;i--) (*l).elem[i]=(*l).elem[i-1]; (*l).elem[p]=x; (*l).kursor=(*l).kursor+1; if((*l).elem[p].sifra==x.sifra) return 1; else return 0; } element DeleteL (element p, lista*l) { if((p<(*l).kursor)&&(p>=0)) { for(int i=p; i<(*l).kursor; i++) (*l).elem[i]=(*l).elem[i+1]; (*l).kursor--; } else { cout<<"Nepostojeci element liste"<<endl; return 0; } } zivotinje RetrieveL (element p, lista *l) { return (*l).elem[p]; } element DeleteallL (lista *l) { (*l).kursor=0; } lista *InitL (lista *l) { l=new lista; (*l).kursor=0; return l; }
You need to login to post a comment.
