Question name - Find the greater element - Topic - Stacks and queues

I asked the question before but i didnt the logic properly, can u tell again in simplified way using stack?

Basically, it is given in the question that you have to determine the next greater element present in the circular array, and if there is no such element found, you have to simply print “-1”. For solving this question, you will need to use a stack, like the first element will be pushed into the stack, and after that you will traverse the array elements starting from index 1, and then check
while(!s.empty() && s.top()<ar[i])
{
cout<<ar[i]<<" ";
s.pop();
}
or if stack is empty, you will simply push the element into the stack,