Queue
|
Stack
|
Queue
is a collection of objects works on mechanism of First In First Out (FIFO)
which means object which is added first, will be removed first.
|
Stack
is collection of objects works on the principle of Last In First Out (LIFO)
which means object which is added first will be removed last.
|
In Queue, Insertion and deletion operation are
performed at different end i.e insertion is performed at one end (front) and
deletion is performed at another end (rear).
|
In
Stack, Insertion and deletion are performed at same end i.e at one side of
the stack (top).
|
Queue consist of two
pointers front and rear. Front points to the first element and rear points to
last element
|
Stack consist of only
one pointer i.e top which points to the last element.
|
Queue is said to be
empty if front is equal to rear.
|
Stack is said to be
empty if top is equal to -1.
|
Real Time Example:-Standing
in line in Bank to deposit amount.
|
Real Time Example:-Distributing
set of plates at the buffet.
|
Technical example:-
sending imq messages
|
Technical
example:-Checking for equal number of parenthesis in an expression.(a+b)
|
Common methods of
queue are:-add(e),remove(),element(),offer(e),poll(),peek().
|
Common methods are
:-push(e),pop(),peek(),empty(),search(e).
|
Enjoy
Reading.
No comments:
Post a Comment