in DS
1,138 views
1 vote
1 vote

What are the minimum number of pointers required to implement a stack using single ended queue ( the queue is NOT a dequeue )?

 

in DS
1.1k views

1 comment

i think 2 , cause if u take 1 pointer then how will get to know whether queue is full or not

i have a doubt that ur question is incomplete
0
0

2 Answers

0 votes
0 votes
As per I think... Its 2 (FRONT and REAR) (If u r thinking of having single pointer then it will not be a queue anymore bcoz queue has enqueue and dequeue operations in constant time).
edited by

3 Comments

I think we need two queues to implement a stack..then shouldn't we consider two sets of front and rear pointer for the two queues?

Then total will be 4..
2
2
true , but thats a bruteforce approach. If we are talking about minimum then one more solution is possible. Try to keep the latest inserted element at the Front pointer.

1: Insert x at rear node

2: perform dequeue followed by enqueue until x reaches the FRONT.
0
0
I was thinking the same. In that case we can get away with just one queue.

However for this to work I think the queue should be circular queue. Otherwise we will quickly reach to the end of queue and no more enque will be possible.
0
0
0 votes
0 votes
since there is no Dequeue then we need three pointers