/ Published in: C++
Implementacija liste pomocu polja.
Expand |
Embed | Plain Text
#include <string> using namespace std; struct animal { int sifra; string naziv; string vrsta; string datum; int cijena; }; struct List { animal polje[10000]; int kursor; }; typedef List Lista; typedef int element; void InitL(Lista *list) { list->kursor = 0; } element FirstL(Lista *list) { return 0; } element EndL(Lista *list) { return list->kursor; } element NextL(element e, Lista *list) { return e+1; } element PreviousL(element e, Lista *list) { return e-1; } int InsertL(animal nova_z, element e, Lista *list) { if (list->kursor == 10000) { return 0; } for (int i = list->kursor; i > e; i--) { list->polje[i] = list->polje[i-1]; } list->polje[e] = nova_z; list->kursor++; return 1; } bool DeleteL(element e, Lista *list) { for (int i = e; i < list->kursor; i++) { list->polje[i] = list->polje[i+1]; } list->kursor--; } void DeleteAll(Lista *list) { list->kursor = 0; } animal RetrieveL(element e, Lista *list) { return list->polje[e]; } element LocateL(animal odbjegla, Lista *list) { for (int i = 0; i < list->kursor; i++) { if (list->polje[i].sifra == odbjegla.sifra) { return i; } } }
You need to login to post a comment.
