/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> using namespace std; struct tpacijent{ int maticni; char ime_prez[40]; int godine; }; tpacijent*pacijent=new tpacijent; tpacijent*pacijent_mladi=new tpacijent; tpacijent*pacijent_novi=new tpacijent; typedef int element; typedef int elementtype; struct lis { tpacijent value; list *next; }; typedef lis list; typedef lis *element; element FirstL(list *L) { return L; } element EndL(list *L) { list *pok; pok = L; while (pok->next) pok = pok->next; return pok; } element NextL(list *current, list *L) { if (current->next != NULL) { list *pok; pok = current->next; return pok; } else { cout << "Ne postoji sljedeci element!" << endl; return NULL; } } element PreviousL(list *current, list *L) { list *pok = L; while ((pok->next != NULL) && (pok->next != current)) pok = pok->next; if (pok != NULL) return pok; else { cout << "Ne postoji prethodni element!" << endl; return NULL; } } element LocateL(elementtype val, list *L) { list *pok; pok = L->next; while ((pok != NULL) && (pok->value != val)) pok = pok->next; if (pok == NULL) cout << "Ne postoji trazeni element" << endl; return pok; } void InsertL(elementtype val, list *p) { list *pok; pok = p->next; list *novi = new list; novi->value = val; p->next = novi; if (pok != NULL) novi->next = pok; else novi->next = NULL; } void DeleteL(list *p, list *L) { list *pok; if (p->next != NULL) { pok = p; pok->next = p->next->next; delete p->next; } else { cout << "Element ne postoji u listi!" << endl; } } elementtype RetrieveL(list *p, list *L) { if (p != NULL) return p->next->value; else { cout << "Ne postoji trazeni element" << endl; return 0; } } void DeleteAllL(list *L) { list *prev, *curr; prev = L; curr = L->next; while (curr) { delete prev; prev = curr; curr = curr->next; } delete prev; L = NULL; } void InitL(list *L) { L->next = NULL; }