/ Published in: C++

Implementacija liste pomoću polja
Expand |
Embed | Plain Text
#include <string> using namespace std; struct ziv{ int sifra; int cijena; char naziv[50]; char vrsta[20]; string datum; }; struct lis{ ziv zivotinje[200]; int cursor; }lista; typedef int tip; int FirstL (lis lista){ return 0; } int EndL( lis lista){ return lista.cursor; } int NextL( int p, lis lista){ return p+1; } int PreviousL(int p, lis lista){ return p-1; } int LocateL( ziv x, lis lista){ for(int i=0; i<lista.cursor; i++){ if(x.sifra==lista.zivotinje[i].sifra) return i;} } int InsertL( ziv x, int p, lis &lista){ lista.cursor++; for (int i=lista.cursor-1;i>p;i--) { lista.zivotinje[i]=lista.zivotinje[i-1]; } lista.zivotinje[p]=x; return 1; } void DeleteL( int p, lis &lista){ for(int i=p;i<lista.cursor;i++) lista.zivotinje[i]=lista.zivotinje[i+1]; lista.cursor--; } ziv RetriveL( int p, lis lista){ return lista.zivotinje[p]; } void DeleteAllL(lis &lista){ lista.cursor=0; } void InitL(lis lista){ lista.cursor=0; }
You need to login to post a comment.