Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4. int main()
  5. {
  6.     stack <int> s;
  7.     s.push(10);
  8.     s.push(20);
  9.     s.push(30);
  10.     /*
  11.     stack <int> :: iterator i;
  12.     for (i=s.begin();i!=s.end;i++){
  13.         cout<<*i;
  14.     }
  15.     */
  16.     cout<<s.top()<<endl;
  17.     s.pop();
  18.     cout<<s.top()<<endl;
  19.     s.pop();
  20.     cout<<s.top()<<endl;
  21.  
  22.     /*
  23.             add
  24.             del
  25.             vu
  26.                     */
  27.  
  28.     char c;
  29.     int y;
  30.     while (true){
  31.         cin>>c>>y;
  32.  
  33.         if (c=='a'){
  34.             s.push(y);
  35.         }
  36.  
  37.         if (c=='d'){
  38.             if(!s.empty()) {
  39.                 s.pop();
  40.                 cout<<s.top()<<endl;
  41.             }
  42.             else{
  43.                     cout<<"the stack is empty"<<endl;
  44.                     break;
  45.             }
  46.         }
  47.  
  48.         if ((c!='a') && (c!='d')) {
  49.             while(!s.empty()){
  50.                 cout<<s.top()<<endl;
  51.                 s.pop();
  52.             }
  53.             break;
  54.         }
  55.         /*
  56.         else {
  57.             cout<<s.top()<<endl;
  58.             s.pop();
  59.             cout<<s.top()<<endl;
  60.             s.pop();
  61.             cout<<s.top()<<endl;
  62.             break;
  63.  
  64.         }
  65.         */
  66.  
  67.     }
  68.  
  69.     cout << "Hello World!" << endl;
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement