/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
typedef int element; struct list { elementtype values[100001]; int cursor; }; int FirstL(list *Li) { return(0); } int EndL(list *Li) { return(Li->cursor); } element NextL(element p, list *Li) { if ((p>=Li->cursor) || (p<0)) { cout << "Nepostojeci element listeNEXT"; system("pause"); exit(0); } else return(p+1); } element PreviousL(element p, list *Li) { if ((p>Li->cursor) || (p<=0)) { cout << "Nepostojeci element listePREV"; system("pause"); exit(0); } else return(p-1); } element LocateL(elementtype x, list *Li) { int i; i=0; while ((i!= Li->cursor) && (Li->values[i]!=x)) i++; return(i); } void InsertL(elementtype x, element p, list *Li) { int i; if ((p<=Li->cursor) && (p>=0) && (Li->cursor<100005)) { for (i=Li->cursor; i>=p; i--) Li->values[i]=Li->values[i-1]; Li->cursor++; Li->values[p]=x; } else { if(Li->cursor>=100005) cout << "Lista je puna"; else cout << "Nepostojeci element listeINSERT"; system("pause"); exit(0); } } void DeleteL(element p, list *Li) { int i; if ((p<Li->cursor) && (p>=0)) { for (i=p; i<Li->cursor; i++) Li->values[i]=Li->values[i+1]; (*Li).cursor--; } else { cout << "Nepostojeci element listeDEL"; system("pause"); exit(0); } } elementtype RetrieveL(element p, list *Li) { if ((p<Li->cursor) && (p>=0)) { return(Li->values[p]); } else { cout << "Nepostojeci element listeRETRIVER"; system("pause"); exit(0); } } void DeleteAllL(list *Li) { Li->cursor=0; } void InitL(list *Li) { Li->cursor=0; }