/ Published in: C++
datoteka zaglavlja lista_polje.h
Expand |
Embed | Plain Text
#include <iostream> #include <cstring> using namespace std; struct podaci{ long sifra; char naziv[50], vrsta[60]; float cijena; int dan, mj, god; };// struct podaci; struct { podaci zivotinje[1000]; int kursor; }Lista; // struct listaP; //ispis liste od kraja int FirstL(){ if (Lista.kursor != 0) return 0; }// FirstL(); int LastL(){ if (Lista.kursor == 0){ return 0; } return Lista.kursor; }// LastL(); int NextL(int pozicija){ if (pozicija >= Lista.kursor || pozicija <0) cout << "Pogreska ! Element je izvan dosega! " << endl; else return pozicija+1; }// NextL(); int PreviousL(int pozicija){ if (pozicija > Lista.kursor || pozicija <=0) cout << "Pogreska ! Element je izvan dosega! " << endl; else return pozicija-1; }// NextL(); int LocateL1(char naziv[]){ int i, j, pozicija; i = FirstL(); j = LastL(); bool nadjeno = false; for (i; i<j; i++) if (strcmp(Lista.zivotinje[i].naziv, naziv) == 0){ pozicija = i; nadjeno = true; break; } if (nadjeno) return i; else return -1; }// LocateL1(); int LocateL2(char naziv[]){ int i, j, pozicija; i = FirstL(); j = LastL(); bool nadjeno = false; for (i; i<j; i++) if (strcmp(Lista.zivotinje[i].vrsta, naziv) == 0){ pozicija = i; nadjeno = true; break; } if (nadjeno) return i; else return -1; }// LocateL2(); int InsertL(int pozicija, podaci P){ int i,j; j = LastL(); if (pozicija < j && pozicija >=0){ for (i = j-1; i >= pozicija; i--){ Lista.zivotinje[i+1] = Lista.zivotinje[i]; } Lista.zivotinje[pozicija] = P; Lista.kursor++; } else if (pozicija == j){ Lista.zivotinje[pozicija] = P; Lista.kursor++; } else return -1; }// InsertL(); int DeleteL1(char naziv[]){ int i, j, pozicija; j = LastL()-1; pozicija = LocateL1(naziv); if(pozicija == -1) return 0; else if(pozicija == j){ Lista.kursor--; return 1; } else if(pozicija >= 0 && pozicija<j){ for(i = pozicija; i<j; i++) Lista.zivotinje[i] = Lista.zivotinje[i+1]; Lista.kursor--; return 1; } }// DeleteL1(); int DeleteL2(char naziv[]){ int i, j, pozicija; j = LastL()-1; pozicija = LocateL2(naziv); if(pozicija == -1) return 0; else if(pozicija == j){ Lista.kursor--; return 1; } else if(pozicija >= 0 && pozicija<j){ for(i = pozicija; i<j; i++) Lista.zivotinje[i] = Lista.zivotinje[i+1]; Lista.kursor--; return 1; } }// DeleteL1(); podaci RetreiveL(int indeks){ if (indeks < 0 || indeks >= Lista.kursor) cout << "Greška!\nIndeks je izvan dosega liste! " << endl; else return Lista.zivotinje[indeks]; }// RetrieveL(); void DeleteAll(){ Lista.kursor = 0; }// DeleteAll(); void InitL(){ Lista.kursor = 0; }// InitL();
You need to login to post a comment.
