Computer Science, asked by Sabbir2263, 1 year ago

How do you represent both stack and queue using a one dimensional array?

Answers

Answered by 247him
2

(assuming that one dimensional array has fixed n elements and no memory re-allocation is allowed )

For stack

keep a pointer to the end

pop operation : end = end - 1

push operation : insert at end , end = end + 1

----------

For queue,

there can be multiple optimal solutions

one of the solution (giving priority to enqueue operation) ->

    keep a pointer to the front and end

   enqueue operation : insert at end , end = end -1

   dequeue operation: front = front + 1

   if ( end reaches max capacity n)

       shift all elements from front to end to 0

(above algorithm can be optimized depending on the priority)

Answered by sk2929542
1

Answer:

Explanation:

Change the following infix expression into postfix expression: A-B(C*D-E)^F/G

Similar questions