Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     list <int> lista;
  9.  
  10.     lista.push_front(1);
  11.     lista.push_front(4);
  12.     lista.push_front(2);
  13.     lista.push_front(9);
  14.     lista.push_front(6);
  15.     lista.push_front(3);
  16.  
  17.     list <int>::iterator it;
  18.  
  19.     cout << "Stos: \n" <<endl;
  20.     for(it=lista.begin(); it!=lista.end(); ++it)
  21.         cout << *it <<'\n';
  22.  
  23.   while(1){
  24.  
  25.         cout << "\n\n[1] Umiesc element na stosie\n[2] Zdejmij element ze stosu\n[3] Wyswietl elementy stosu\n[0] Zakoncz\n" <<endl;
  26.         int opcja,opcja2,a;
  27.         cin >> opcja;
  28.  
  29.         switch(opcja)
  30.         {
  31.         case 1:
  32.             cout << "[1] Umiesc na poczatku\n[2] Umiesc na koncu" <<endl;
  33.             cin >> opcja2;
  34.             if(opcja2 == 1)
  35.             {
  36.                 cout << "Podaj liczbe: " <<endl;
  37.                 cin >> a;
  38.                 lista.push_front(a);
  39.                 break;
  40.             }
  41.             else if(opcja2 == 2)
  42.             {
  43.                 cout << "Podaj liczbe: " <<endl;
  44.                 cin >> a;
  45.                 lista.push_back(a);
  46.                 break;
  47.             }
  48.             else
  49.                 break;
  50.  
  51.         case 2:
  52.             cout << "[1] Zdejmij z poczatku\n[2] Zdejmij z konca" <<endl;
  53.             cin >> opcja2;
  54.             if(opcja2 == 1)
  55.             {
  56.                 lista.pop_front();
  57.                 break;
  58.             }
  59.             else if(opcja2 == 2)
  60.             {
  61.                 lista.pop_back();
  62.                 break;
  63.             }
  64.             else
  65.                 break;
  66.  
  67.         case 3:
  68.             cout << "Stos: \n" <<endl;
  69.             for(it=lista.begin(); it!=lista.end(); ++it)
  70.             cout << *it <<'\n';
  71.             break;
  72.  
  73.         case 0:
  74.             return 0;
  75.     }
  76.   }
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement