Suppose I have a queue where I pull from left and push to the right, and suppose I have the contents in the queue as $a b c @ d e$ (from left to right, left is head, right is tail).
Is there a simple algorithm that doesn't require extra structures that makes $e$ at the head? meaning to get us to the queue $eabc@d$?
P.S.: I need an algorithm like that for the purpose of a queue automaton.
Asked By : TheNotMe
Answered By : Gari BN
If you can only push (enqueue) or pull (dequeue) from the queue, then your only option is to pull all the elements and re-enter them.
If you need such an operation, you can use deque (double-ended queue). See: http://en.wikipedia.org/wiki/Double-ended_queue .
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/19452
0 comments:
Post a Comment
Let us know your responses and feedback