@Shikhar....
1) Push the first element to stack.
2) for i = 1 to n-1
a) temp =a[i]
b) while(stack not empty)
int x = pop(&stack)
if(x>temp) print(temp);
else
push(x,stack)
break;
c) push(temp,stack)
3) After the loop in step 2 is over, pop all the elements from stack and
print -1 as next element for them.
--
*Piyush Sinha*
*IIIT, Allahabad*
*+91-7483122727*
* <https://www.facebook.com/profile.php?id=100000655377926> "NEVER SAY
NEVER"
*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.