a)
Character Comes to Scan | Stack Holds |
Postfix Expression |
( |
( |
|
A |
( |
A |
+ |
(+ |
A |
B |
(+ |
AB |
) |
Empty |
AB+ |
* |
* |
AB+ |
C |
* |
AB+C |
- |
- |
AB+C* |
( |
-( |
AB+C* |
D |
-( |
AB+C*D |
- |
-(- |
AB+C*D |
E |
-(- |
AB+C*DE |
) |
- |
AB+C*DE- |
/ |
-/ |
AB+C*DE- |
( |
-/( |
AB+C*DE- |
F |
-/( |
AB+C*DE-F |
+ |
-/(+ |
AB+C*DE-F |
G |
-/(+ |
AB+C*DE-FG |
) |
-/ |
AB+C*DE-FG+ |
|
Empty |
AB+C*DE-FG+/- |
A double-ended queue is an abstract data type similar to an ordinary queue, except that it allows you to insert and delete from both sides.This differs from a normal queue, where elements can only be added to one end and removed from the other. Both queues and stacks can be considered specializations of dequeue, and can be implemented using dequeue.