Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- int main()
- {
- list <int> lista;
- lista.push_front(1);
- lista.push_front(4);
- lista.push_front(2);
- lista.push_front(9);
- lista.push_front(6);
- lista.push_front(3);
- list <int>::iterator it;
- cout << "Stos: \n" <<endl;
- for(it=lista.begin(); it!=lista.end(); ++it)
- cout << *it <<'\n';
- while(1){
- cout << "\n\n[1] Umiesc element na stosie\n[2] Zdejmij element ze stosu\n[3] Wyswietl elementy stosu\n[0] Zakoncz\n" <<endl;
- int opcja,opcja2,a;
- cin >> opcja;
- switch(opcja)
- {
- case 1:
- cout << "[1] Umiesc na poczatku\n[2] Umiesc na koncu" <<endl;
- cin >> opcja2;
- if(opcja2 == 1)
- {
- cout << "Podaj liczbe: " <<endl;
- cin >> a;
- lista.push_front(a);
- break;
- }
- else if(opcja2 == 2)
- {
- cout << "Podaj liczbe: " <<endl;
- cin >> a;
- lista.push_back(a);
- break;
- }
- else
- break;
- case 2:
- cout << "[1] Zdejmij z poczatku\n[2] Zdejmij z konca" <<endl;
- cin >> opcja2;
- if(opcja2 == 1)
- {
- lista.pop_front();
- break;
- }
- else if(opcja2 == 2)
- {
- lista.pop_back();
- break;
- }
- else
- break;
- case 3:
- cout << "Stos: \n" <<endl;
- for(it=lista.begin(); it!=lista.end(); ++it)
- cout << *it <<'\n';
- break;
- case 0:
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement