momo2345

special task

Aug 14th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. void push(int a);
  5. bool isFull(int n);
  6. bool isEmpty();
  7. int pop();
  8. int getMin();
  9. //This is the STL stack (http://quiz.geeksforgeeks.org/stack-container-adaptors-the-c-standard-template-library-stl/).
  10. stack<int> s;
  11. int main(){
  12.     int t;
  13.     cin>>t;
  14.     while(t--){
  15.         int n,a;
  16.         cin>>n;
  17.         while(!isEmpty()){
  18.             pop();
  19.         }
  20.         while(!isFull(n)){
  21.             cin>>a;
  22.             push(a);
  23.         }
  24.         cout<<getMin()<<endl;
  25.     }
  26. }// } Driver Code Ends
  27.  
  28.  
  29. /*Complete the function(s) below*/
  30. void push(int a)
  31. {
  32.      //add code here.
  33.      s.push(a);
  34. }
  35.  
  36. bool isFull(int n)
  37. {
  38.      //add code here.
  39.      if(s.size()==n)
  40.      return 1;
  41.      else return 0;
  42. }
  43.  
  44. bool isEmpty()
  45. {
  46.     //add code here.
  47.     if(s.empty()) return 1;
  48.     else return 0;
  49. }
  50.  
  51. int pop()
  52. {
  53.     //add code here.
  54.     s.pop();
  55. }
  56.  
  57. int getMin()
  58. {
  59.    //add code here.
  60.    int a=s.top();
  61.    while(!s.empty()){
  62.    int b=s.top();
  63.      a=min(a,b);
  64.    s.pop();}
  65.    return a;
  66. }
Add Comment
Please, Sign In to add comment