Adrita

task 6( ds lab 4) 3rd sem

Feb 17th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void PrintNGE(int arr[],int n)
  4. {
  5. stack <int> s;
  6. s.push(arr[0]);
  7. for(int i=1; i<n; i++)
  8. {
  9. if(s.empty())
  10. {
  11. s.push(arr[i]);
  12. continue;
  13. }
  14. while(s.empty()==false && s.top()<arr[i])
  15. {
  16. cout<<s.top()<<" NGE "<<arr[i]<<endl;
  17. s.pop();
  18. }
  19. s.push(arr[i]);
  20. }
  21. while(s.empty()==false)
  22. {
  23. cout<<s.top()<<" NGE -1"<<endl;
  24. s.pop();
  25. }
  26. }
  27. int main()
  28. {
  29. int t;
  30. cin>>t;
  31. for(int i=0; i<t; i++)
  32. {
  33. int arr[100],n=0;
  34. for(int j=0;; j++)
  35. {
  36. int a;
  37. cin>>a;
  38. if(a>-1)
  39. {
  40. arr[j]=a;
  41. n++;
  42. }
  43. else
  44. break;
  45. }
  46. PrintNGE(arr,n);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment