For an assignment I have to implement a simple queue using a class.
I'm having problem with this assignment though. The queue I wrote actually handles the data in first-in-last-out ( FILO ) order. So it's more a stack then a queue.
The problem is that I can't figure out why it works in this way; If I look at my program I would really be sure that I'm doing things correctly. But for some reason I don't.
That is because of the order of evaluation. Means the last 'get()' is called first. So don't modify the contents of a class within a get() function. better break it in 2 function like top() and pop().
do you know that stl already provides stack and queue?
Nevertheless, this behaviour is extremely odd and I wonder where this behaviour would be useful.
I also know about the queue class the STL provides. But this isn't production code, it's just an exercise we needed to do to practise writing useful classes :)
You may want to modify your queue so get() an put() work in constant time.
Just keep two indices (top, bottom) and use modulo operator to recycle the cells