Advertisement
Adrita

task 1( ds lab 4) 3rd sem

Jan 30th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int N;
  4. void push(int s[],int &top,int item)
  5. {
  6. if(top>=N)
  7. cout<<"Full"<<endl;
  8. else
  9. {
  10. s[top]=item;
  11. top++;
  12. }
  13. }
  14. int pop(int s[],int &top)
  15. {
  16. if(top==0)
  17. cout<<"Empty"<<endl;
  18. else
  19. {
  20. --top;
  21. return s[top];
  22. }
  23. }
  24. int main()
  25. {
  26. cin>>N;
  27. int t,i,ar[N],top=0,j;
  28. cin>>t;
  29. for(i=0; i<t; i++)
  30. {
  31. cout<<"Enter 1 to push and 2 to pop"<<endl;
  32. int a;
  33. cin>>a;
  34. if(a==1)
  35. {
  36. cout<<"Enter number"<<endl;
  37. int b;
  38. cin>>b;
  39. push(ar,top,b);
  40. }
  41. else
  42. pop(ar,top);
  43. cout<<"size= "<<top;
  44. cout<<" items= ";
  45. if(top==0)
  46. cout<<"NULL"<<endl;
  47. else
  48. {
  49. for(j=0; j<top; j++)
  50. {
  51. cout<<ar[j]<<" ";
  52. }
  53. cout<<"\n";
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement