How to do this with satcks?

I have done this with arrays but what’s the other approach?

Hello @zabhishek first take a input array
and a stack< int > s;
push the first index of array into the stack like s.push(a[0]);
apply loop from i=1 to n
now apply a while loop
while(!s.empty()&&s.top()<a[ i ])
{
cout<<a[ i ]<<" “;
now pop the current element from the stack reason for that we want to check for next element
s.pop();
}
push the next element of the array according to loop
s.push( a[ i ] );
while(! s.empty() )
{
cout<<-1<<” ";
s.pop();
}

i tried this approach but it is not working for the case of circular array.

@zabhishek in this do with indexing through which you can access the index and the element as well.
check this code:
https://ide.codingblocks.com/s/430946

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.