Hi,
i'm a student and got an assignment, and was wandering what is the best way to design it, or simply put - what would a skilled programmer do?
here goes: (it's a bit long, so sorry in advance and thank you)
i have to create 2 containers as templates one of Queue and the other of Priority Queue (which is a queue with sorted items)
Oueue has these Methods:
Push - push into back of queue
Pop - remove item from top of queue
Front - inspect item in front
Back - inspect item in back
pQueue has these Methods:
Push - push into a sorted place in the queue (the item i'll be inserting will have operator< to comare)
Pop - remove item from top of queue
Front - inspect item in front
that's it...
notice that pQueue does not have a Back method and is not allowed to have one such as public, moreover no other public methods are allowed to exist for any client of these container classes.
hese is what i did:
i created a BaseQueue that stores the data in linked list with Elm *head, *tail and the methods:
Push - into the back of the Queue
Pop - the same thing in both containers
Front - the same thing in both containers
and inherited public from this one into pQueue and Queue.
the problem was that in order to get into the middle/end of this queue i'll have to throw out all items and put them in a temp queue and then return them back to the original queue when i'm done. --- This was a big problem with pQueue because i has to play with the entier Queue to search for the right position to insert the value, (pop out until i find the right place) and Back at queue not much simpler...
So.... is this a good way of doing this? (even though it has a very bad performence considering i'm poping and pushing back everything just to insert one item in pqeueu and running all the list to get to back in queue)
Any other suggestion or better way? i couldn't think of any...
Thanks in advance...
Koren. :-)