/ Published in: C++
zadatak za Sp
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <cstring> struct zivotinje { int sifra, cijena, d, m, g; char naziv [20], vrsta [30]; }; zivotinje ziv; struct LIST { int sifra[1000], cijena[1000], d[1000], m[1000], g[1000]; char naziv [20][1000], vrsta [30][1000]; int pointer; }; typedef int element; element ENDL (LIST *L) { return L->pointer; } element FIRSTL (LIST *L) { if (L->pointer == 0) ENDL(L); return 0; } element NEXTL (element position, LIST *L) { if ((position >= L->pointer) || (position < 0)) return 0; return(position + 1); } element PREVIOUSL (element position, LIST *L) { if ((position > L->pointer) || (position <= 0)) return (position - 1); } element LOCATEL (zivotinje z, LIST *L) { int br = 0; while ((br != L->pointer) && (L->sifra[br]!= z.sifra)) br ++; return br; } element INSERTL (zivotinje z, element position, LIST *L) { int br; if ((position <= L->pointer) && (position >= 0)) { for (br=L->pointer; br >= position; br --) { L->sifra[br] = L->sifra[br-1]; L->cijena[br] = L->cijena[br-1]; L->d[br] = L->d[br-1]; L->m[br] = L->m[br-1]; L->g[br] = L->g[br-1]; strcpy (L->naziv[br],L->naziv[br-1]); strcpy (L->vrsta[br],L->vrsta[br-1]); } L->pointer ++; L->sifra[position] = z.sifra; L->cijena[position] = z.cijena; L->d[position] = z.d; L->m[position] = z.m; L->g[position] = z.g; strcpy (L->naziv[position],z.naziv); strcpy (L->vrsta[position],z.vrsta); return 1; } else return 0; } element DELETEL (element position, LIST *L) { int br; if ((position < L->pointer) && (position >= 0)) { for (br = position; br < L->pointer; br ++){ L->sifra[br] = L->sifra[br+1]; L->cijena[br] = L->cijena[br+1]; L->d[br] = L->d[br+1]; L->m[br] = L->m[br+1]; L->g[br] = L->g[br+1]; strcpy(L->naziv[br],L->naziv[br+1]); strcpy(L->vrsta[br],L->vrsta[br+1]); } L->pointer --; return 1; } else return 0; } zivotinje RETRIEVEL (element position, LIST *L) { if ((position < L->pointer) && (position >= 0)) { ziv.sifra = L->sifra[position]; ziv.cijena = L->cijena[position]; ziv.d = L->d[position]; ziv.m = L->m[position]; ziv.g = L->g[position]; strcpy(ziv.naziv,L->naziv[position]); strcpy(ziv.vrsta,L->vrsta[position]); return ziv; } } element DELETEALLL (LIST *L) { L->pointer = 0; return 0; } LIST *INITL (LIST *L) { L = new LIST; L->pointer = 0; return L; }
URL: mhudince2