/ Published in: C++
Implementacija liste pomocu pokazivaca
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <string> using namespace std; struct animal { int sifra; string naziv; string vrsta; string datum; int cijena; }; struct List { animal a; List *next; }; typedef List Lista; typedef List* element; element GRESKA; void InitL(Lista *list) { element novi = new Lista; novi->next = NULL; list->next = novi; } element FirstL(Lista *list) { return list->next; } element EndL(Lista *list) { element tekuci = list->next; while (tekuci->next != NULL) { tekuci = tekuci->next; } return tekuci; } element PreviousL(element e, Lista *list) { element tekuci = list; while (tekuci->next != e) { tekuci = tekuci->next; } return tekuci; } int InsertL(animal nova_z, element e, Lista *list) { element novi = new Lista; novi->a = nova_z; novi->next = e; element prethodni = PreviousL(e, list); prethodni->next = novi; return 1; } bool DeleteL(element e, Lista *list) { element tekuci = list; while (tekuci->next != e) { tekuci = tekuci->next; } tekuci->next = e->next; delete e; return true; } void DeleteAll(Lista *list) { element tekuci, brisi; tekuci = list->next; while(tekuci != NULL) { brisi = tekuci; tekuci = tekuci->next; delete brisi; } element zadnji = new Lista; zadnji->next = NULL; list->next = zadnji; } element LocateL(animal odbjegla, Lista *list) { element tekuci; tekuci = list->next; while (tekuci != EndL(list)) { if (tekuci->a.sifra == odbjegla.sifra) { return tekuci; } tekuci = tekuci->next; } return GRESKA; } element NextL(element e, Lista *list) { return e->next; } animal RetrieveL (element e, Lista *list) { return e->a; }