I am unable to make any logical algorithm to access middle of stack. Please guide some with examples. I am using stack implemented with linkedlists, I have following functions available for stack like push,pop,top.
First you have to find out how large the stack is; you can do this by popping elements off the stack and pushing them onto a temp stack. Once you know how big it is, you can figure out which nth item is the middle. Then you just pop off the temp stack, pushing into the original stack again, until you get the middle element. Once you've got that, deal with it, then continue pushing back onto the original stack.
By the end, you have everything back the way it was and you have already accessed the middle element.