Advertisement
sajid161

11:2

Jan 8th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 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.      s.push (a);
  33. }
  34.  
  35. bool isFull(int n)
  36. {
  37.      return n == s.size();
  38. }
  39.  
  40. bool isEmpty()
  41. {
  42.     return s.empty();
  43. }
  44.  
  45. int pop()
  46. {
  47.     s.pop();
  48. }
  49.  
  50. int getMin()
  51. {
  52.     int mn = 2e9;
  53.    
  54.     while ( !s.empty() ) {
  55.         mn = min ( s.top(), mn );
  56.         s.pop();
  57.     }
  58.    
  59.     return mn;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement