Advertisement
Adrita

task 2( ds lab 4) 3rd sem

Jan 30th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. int N;
  5. void showstack(stack <int> s)
  6. {
  7. while (!s.empty())
  8. {
  9. cout << s.top()<<" ";
  10. s.pop();
  11. }
  12. cout << '\n';
  13.  
  14. }
  15. int main()
  16. {
  17. cin>>N;
  18. stack <int> s;
  19. int t,i;
  20. cin>>t;
  21. for(i=0; i<t; i++)
  22. {
  23. cout<<"Enter 1 to push and 2 to pop"<<endl;
  24. int a;
  25. cin>>a;
  26. if(a==1)
  27. {
  28. cout<<"Enter number"<<endl;
  29. int b;
  30. cin>>b;
  31. s.push(b);
  32. }
  33. else
  34. s.pop();
  35. cout << "size= " << s.size();
  36. cout<<" items= ";
  37. if(!s.empty())
  38. showstack(s);
  39. else
  40. cout<<"NULL"<<endl;
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement