Hi sorthon123, I have a couple of questions about your code:
1) Why do you allocate 3 nodes when you are pushing only 1 item onto the list?
I'm referring to lines 55-57 in your pushqueue():
1 2 3
|
node<type> *t = new node<type>;
node<type> *tmp = new node<type>;
node<type> *trail = new node<type>;
|
One new node is enough to store one new item + one pointer to the next node.
2) What exactly is the role of priority in your node structure? It looks like you want to use it to determine where to insert a new node in the existing list. Is this right?
If so, why is it a <type> object?
I see that the 2nd argument in your calls to pushqueue() in main() is an integer. This is what you are passing as a <type> object for priority.
I'm assuming that the integers are meant to determine the order of the items in the list so that this code:
1 2 3 4 5 6
|
b.pushqueue('6',3);
cout<<endl;
b.pushqueue('@',4);
cout<<endl;
b.pushqueue('b',2);
b.view();
|
would produce:
Is that right?
I'm replying because I just wrote an ordered list template class which is working well, so maybe I can help. The way I did the ordering of items was to rank them using the < operator, which must be overloaded in the <type> class. This works very naturally. The property determining priority (node order) should belong to the <type> object, not the node object.
Let me know if you wish to compare methods.