I've just got a quick question regarding this--specifically, my algorithm. Is there a flaw in it, or is there an easier way to compare the two?
Basically, this function's supposed to check whether a stack and a queue have been inserted in the same order.
- First, determine whether if they have the same number of items using size(). If they don't, return false.
- Next, create a temporary stack.
- Using a for loop, pop off an item at a time on the stack and put it onto the temporary stack until the stack is empty.
- Compare the stack and the queue using pop (or whatever queue uses; I can't remember from the top of my head) if they're the same.
Seems like a very strange assignment to me and where is your algorithm that you said you posted? A queue uses deque by default but since it is an adapter container it could be whatever you want provided that it meets queue's requirements.
Err...that was kind of my algorithm in the first post. It's all of those dashes/bullets. I haven't started coding it yet; I've just wanted to make sure if it seemed okay or not.
The professor wants us to use queues. He really didn't specify deques and we haven't really gone over deques, so I'm assuming he wants just queues and stacks.
Anyway, my question's still unanswered. Is there a potential flaw/bug I could come upon if I do it this way?