Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct cvor
- {
- int Info;
- cvor * next;
- };
- void Dodaj_na_kraj(int v, cvor * &Lista, cvor * &temp)
- {
- temp = Lista;
- if (Lista == NULL) //poseban slucaj: kada je lista prazna
- {
- Lista = new cvor();
- Lista->Info = v;
- Lista->next = NULL;
- }
- else
- {
- while (temp->next != NULL)
- {
- temp = temp->next;
- }
- cvor * m;
- m = new cvor();
- temp->next = m;
- temp = m;
- temp->Info = v;
- }
- }
- int Ukloni_sa_kraja(cvor * &Lista)
- {
- cvor * pok = NULL;
- cvor * pok1 = NULL;
- pok = Lista;
- if (Lista == NULL) //1. izuzetak: kada je lista prazna
- {
- cout << "PRAZNO" << endl;
- return 0;
- }
- else if (Lista->next == NULL) //2. izuzetak: lista ima samo jedan element
- {
- int x = Lista->Info;
- delete Lista;
- Lista = NULL;
- return x;
- }
- else
- {
- pok1 = pok->next;
- while (pok1->next != NULL)
- {
- pok = pok1;
- pok1 = pok->next;
- }
- pok->next = NULL;
- int x = pok1->Info;
- delete pok1;
- return x;
- }
- }
- int ukloni_predzanji(cvor * &Lista){
- }
- int ukloni_drugi(cvor* &Lista)
- void ispis(cvor * &Lista) // Kod iz materijala sa predavanja
- {
- cvor * pok;
- pok = Lista;
- while (pok != NULL)
- {
- cout << pok->Info << ", ";
- pok = pok->next;
- }
- }
- void main()
- {
- cvor * Lista = NULL;
- cvor * temp = NULL;
- /*testiram mogu li izbrisati cvor iz prazne liste*/
- Ukloni_sa_kraja(Lista);
- Dodaj_na_kraj(3, Lista, temp);
- ispis(Lista);
- cout << endl;
- Dodaj_na_kraj(5, Lista, temp);
- ispis(Lista);
- cout << endl;
- Dodaj_na_kraj(7, Lista, temp);
- ispis(Lista);
- cout << endl;
- Dodaj_na_kraj(9, Lista, temp);
- ispis(Lista);
- cout << endl;
- cout << "\n***************\n";
- cout << "brisem: " << Ukloni_sa_kraja(Lista) << endl;
- ispis(Lista);
- cout << endl;
- cout << "brisem: " << Ukloni_sa_kraja(Lista) << endl;
- ispis(Lista);
- cout << endl;
- cout << "brisem: " << Ukloni_sa_kraja(Lista) << endl;
- ispis(Lista);
- cout << endl;
- //testiram mogu li izbrisati cvor iz liste koja ima samo jedan cvor
- cout << "brisem: " << Ukloni_sa_kraja(Lista) << endl;
- ispis(Lista);
- cout << endl;
- //ponovo testiram mogu li brisati praznu listu
- cout << "brisem: " << Ukloni_sa_kraja(Lista) << endl;
- ispis(Lista);
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment