Assume you have a stack and a queue implemented using an array of size 4. show the content of the array for the stack (then the queue) for the following operations: (for the queue replace push by add and pop by remove; keep in mind that the queue uses a circular array): push(-3), push(-5), push(-9), push(-10), pop(), pop(), push(-13), pop(), push( -15), push(-17).
Ans
Stack operation performed on top of stack.
push increment top and insert element
pop remove element and decrement top.
,
Queue has two ends Front and Rear.
Insertion take place at rear and rear update as (rear+1)%size
Removal take place at front. Front update as (front+1)%capacity.
.
If any doubt ask in the comments.
Get Answers For Free
Most questions answered within 1 hours.