#include #include #include typedef struct elem { int broj; struct elem *pret; struct elem *sled; }Elem; void pisi(Elem* lst){ while(lst){ cout<<" "<broj; lst=lst->sled; } } Elem* naKraj(Elem** lst, int broj){ Elem* tek = *lst, *novi; while(tek && tek->sled)tek=tek->sled; novi=new Elem; novi->sled = NULL; novi->pret = tek; novi->broj = broj; if(!(*lst))*lst=novi; else tek->sled=novi; return *lst; } Elem* naPocetak(Elem** lst, int broj){ Elem* novi; novi=new Elem; novi->broj = broj; novi->sled = *lst; novi->pret = NULL; if(*lst)(*lst)->pret=novi; *lst=novi; return *lst; } int saPocetka(Elem** lst){ if(*lst == NULL)exit(1); else{ Elem* pret = *lst; int broj = (*lst)->broj; *lst = (*lst)->sled; delete pret; return broj; } return 0; } int saKraja(Elem** lst){ if(*lst == NULL)exit(1); else{ Elem* tek=*lst, *pret=NULL; int broj; while(tek && tek->sled){ pret = tek; tek=tek->sled; } broj = tek->broj; if(!pret)*lst = NULL; else pret->sled = NULL; return broj; } return 0; } // ----------------------------------- // MAIN FUNKCIJA // ----------------------------------- main(){ int broj, kraj=0, izbor; Elem *lst=NULL; while(!kraj){ cout<<"\n 1. DODAJ NA POCETAK\n" <<" 2. DODAJ NA KRAJ\n" <<" 3. OBRISI BR. S POCETKA LISTE\n" <<" 4. OBRISI BR. S KRAJA LISTE\n" <<" 5. ISPISI ELEMENTE LISTE\n" <<" 0. IZLAZ\n\n"; cout<<"Tvoj izbor je: "; cin>>izbor; switch(izbor){ case 1: cout<<"Unesi broj: "; cin>>broj; naPocetak(&lst,broj); break; case 2: cout<<"Unesi broj: "; cin>>broj; naKraj(&lst,broj); break; case 3: saPocetka(&lst); break; case 4: saKraja(&lst); break; case 5: cout<<"\nLista: \n"; pisi(lst); break; case 0: break; } getch(); } }