In: Computer Science
How do we define the stack ADT, including its operations? Typed please.
Stack is a LIFO( Last In First Out) data structure.Elements can be inserted and deleted from one end that is top.
Every new element inserted is placed on top of the stack.
” Top” is used to point to element on the top of the stack.
stack may sometimes reach overflow state, which means stack is full.
it may also reach” underflow” state, means stack is empty.
Ther is need to keep track of state of stack whether isfull or is empty before performing insertion and deletion.
insertion of an element is PUSH operation.
deletion is POP operation.
To access top element without deleting it is a PEEK operation.
stack ADT includes all these operations as follows:
1. Create( ) : to create a new empty stack and returns address of stack.
2. Push(type element ): To insert element on top of stack
3. Pop(): deletes and returns top element in stack.
4. Peek( ): returns top element of stack without deleting it.
5. IsFull(): returns true if stack is full else false
6. IsEmpty(): returns true if stack is empty else false.