Design a stack with operations on middle element How to implement a stack which will support following operations in O(1) time complexity? 1) push() which adds an element to the top of stack. 2) pop() which removes an element from top of stack. 3) findMiddle() which will return middle element of the stack. 4) deleteMiddle() which will delete the middle element. Push and pop are standard stack operations. The important question is, whether to use a linked list or array for implementation of stack? Please note that, we need to find and delete middle element.
Read full article from Design a stack with operations on middle element | GeeksforGeeks
No comments:
Post a Comment