/ Published in: C++
Implementacije liste pomoću polja
Expand |
Embed | Plain Text
#ifndef _LISTA_POLJE_H_ #define _LISTA_POLJE_H_ struct _tempList { int sifra; std::string naziv,vrsta,datum; float cijena; }; struct _list { _tempList a[50]; int next; }; typedef int List; typedef _list Array; int FirstL(_list *list) { return 0; } int EndL(_list *list) { return list->next; } int NextL(int temp,_list *list) { if (temp == EndL(list)) return 0; return temp+1; } int PreviousL(int temp,_list *list) { if (temp == FirstL(list)) return 0; return temp-1; } int LocateL(int temp,_list *list) { for (int i =0;i<EndL(list);i++) { if (list->a[i].sifra == temp) return i; } return EndL(list); } int LocateL(float temp,_list *list) { for (int i = 0;i<EndL(list);i++) { if (list->a[i].cijena == temp) return i; } return EndL(list); } int LocateL(std::string temp,_list *list) { for (int i = 0;i<EndL(list);i++) { if (list->a[i].datum == temp || list->a[i].naziv == temp|| list->a[i].vrsta == temp) return i; } } bool InsertL(_tempList copyElement,int index,_list *list) { if (list->next == 0) list->a[index] = copyElement; else { for (int i = EndL(list); i > index; i--) list->a[i] = list->a[i-1]; list->a[index] = copyElement; } list->next++; return true; } bool DeleteL(int index,_list *list) { //index preko locate for (int i = index; i<EndL(list);i++) list->a[i] = list->a[i+1]; list->next--; return true; } bool DeleteAllL(_list *list) { list->next = 0; return true; } _tempList RetrieveL(int index,_list *list) { return list->a[index]; } bool InitL(_list *list) { list->next = 0; return true; } #endif
You need to login to post a comment.
