Definition of stack:
Stack is a special type of data structure where elements are inserted from one end and elements are deleted from the same end. The position from where elements a are inserted and from where elements are deletedis termed as top of the stack. Thus stack is a homogeneous collection of elements of any one type, arranged linearly with access at one end only.
Stack is also called the LIFO. That means Last On First Out. Which elements enter to the stack at last, will out first from the stack.
Stack has basically two methods, methods are-
- Push: Inserting an item to the stack
- Pop: Deleting an item from the stack
Stack push() method:
Before push the value stack top
was = 5 || After push 20 the stack, now top is 20
1. Push Option for stack:
- void push(K o)
- Pushes the given object on the stack.
- Parameters:
o
- the object that will become the new top of the stack.
2.Pop Option in stack:
- K pop()
- Pops the top off the stack.
- Returns:
- the top of the stack.
No comments:
Post a Comment