Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<stack>
- using namespace std;
- int * find(int *p, int n){
- int *a = new int[n];
- stack<int> s;
- s.push(0);
- for(int k = 0,i = 1; k != i ; i = (i+1) % n){
- if(s.top()< p[i] ){
- while(s.top()<p[i] && !s.empty()){
- a[s.top()] = i;
- s.pop();
- // cout<<"Hello2"<<endl;
- }
- //After here the their is abnormal termination
- cout<<"Hello3"<<endl;
- s.push(i);
- // cout<<"Hello4"<<endl;
- k = i;
- }
- else
- s.push(i);
- }
- a[s.top()] = -1;
- s.pop();
- return a;
- }
- int main() {
- int n;
- cin>>n;
- int *a = new int[n];
- for(int i = 0; i < n; i++)
- {
- cin>>a[i];
- }
- int *k = find(a, n);
- for(int i = 0; i < n; i++)
- cout<<a[i]<<" ";
- return 0;
- }
Add Comment
Please, Sign In to add comment