Array implementation of StackIn array implementation, the stack is formed by using the array. All the operations regarding the stack are performed using arrays. Lets see how each operation can be implemented on the stack using array data structure. Adding an element onto the stack (push operation)Adding an element into the top of the stack is referred to as push operation. Push operation involves following two steps.
Stack is overflown when we try to insert an element into a completely filled stack therefore, our main function must always avoid stack overflow condition. Algorithm: Time Complexity : o(1) implementation of push algorithm in C languageDeletion of an element from a stack (Pop operation)Deletion of an element from the top of the stack is called pop operation. The value of the variable top will be incremented by 1 whenever an item is deleted from the stack. The top most element of the stack is stored in an another variable and then the top is decremented by 1. the operation returns the deleted value that was stored in another variable as the result. The underflow condition occurs when we try to delete an element from an already empty stack. Algorithm : Time Complexity : o(1) Implementation of POP algorithm using C languageVisiting each element of the stack (Peek operation)Peek operation involves returning the element which is present at the top of the stack without deleting it. Underflow condition can occur if we try to return the top element in an already empty stack. Algorithm : PEEK (STACK, TOP) Time complexity: o(n) Implementation of Peek algorithm in C languageC program Java Program C# Program
Next TopicDS Linked List Implementation of Stack
