how can I implement stack with one queue?
the queue only can enqueue and dequeue
sahar.97 0 Newbie Poster
Recommended Answers
Jump to PostThe pop function generally is just removing the most recently added (push) member of the queue/stack and returning it to the caller.
Jump to PostHow to pop from a queue that just supports enqueue/dequeue:
Hint:
You can extract any arbitrary member of a queue,eg nth member, by cycling the queue, ie dequeing and immediately re-enqueing n-1 members, then the next dequeue is the desired member. (If that wasn't the last member then you also …
Jump to PostOh wow, if you can't query the size of the queue that makes it harder.
Maybe you could keep your own counter of the number of elements in the queue?
Alternatively you could use the second approach (add new items at the front of the queue by adding it at …
All 10 Replies
Stuugie 50 Marketing Strategist
sahar.97 0 Newbie Poster
Stuugie 50 Marketing Strategist
sahar.97 0 Newbie Poster
Stuugie 50 Marketing Strategist
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
sahar.97 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
sahar.97 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.