Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main()
- {
- stack <int> s;
- s.push(10);
- s.push(20);
- s.push(30);
- /*
- stack <int> :: iterator i;
- for (i=s.begin();i!=s.end;i++){
- cout<<*i;
- }
- */
- cout<<s.top()<<endl;
- s.pop();
- cout<<s.top()<<endl;
- s.pop();
- cout<<s.top()<<endl;
- /*
- add
- del
- vu
- */
- char c;
- int y;
- while (true){
- cin>>c>>y;
- if (c=='a'){
- s.push(y);
- }
- if (c=='d'){
- if(!s.empty()) {
- s.pop();
- cout<<s.top()<<endl;
- }
- else{
- cout<<"the stack is empty"<<endl;
- break;
- }
- }
- if ((c!='a') && (c!='d')) {
- while(!s.empty()){
- cout<<s.top()<<endl;
- s.pop();
- }
- break;
- }
- /*
- else {
- cout<<s.top()<<endl;
- s.pop();
- cout<<s.top()<<endl;
- s.pop();
- cout<<s.top()<<endl;
- break;
- }
- */
- }
- cout << "Hello World!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement