Thread: double queue
View Single Post
  #2 (permalink)  
Old April 6th, 2004, 01:08 PM
nikolai nikolai is offline
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Without looking too closely at your code, I would suggest keeping an extra pointer. One pointer will point to the front of the queue, the other to the back. This means that you can quickly perform push and pop operations at both ends.

You don't care about the stuff in the middle, because a queue (by definition) can only insert and remove at one end.

You'll end up having functions like push_front(), pop_front(), push_back(), pop_back() instead of push() and pop(). These allow the programmer using your queue to determine which end of the queue to push and pop from.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote