Hi, i'm really stuck with this linked list and i feel tottaly out of my depth.

Hopefully i can get it a bit clearer! what im trying to do is a print simulation with three priorities and im trying to make the linked list to act like the queue so a job with priority 1 goes first and priority 3 goes last, any ideas?

## All 8 Replies

>>any ideas

Yes -- post code.

thanks for replying this is all I have.. i have no idea how to do the above problem..

{

liData *newItem = new liData;
newItem->PrintItem.jobNo = theID;
}

that will probably work to just add the new node to the head of the linked list. To add in priority order you would have to transverse (iterate) the list and find the spot where the new node has to be inserted.

Does that mean just searching through the list to find the appriopriate priority? (im generating the list using the RAND)

>>Does that mean just searching through the list to find the appriopriate priority

Yes.

Thanks ancient dragon for your previous help

After spending all night trying to think about this I still can't get it at all and im starting to give up can anyways please help as to how i would insert by priority in the linked list? priorties one to three, even an algorithm?

assuming jobNo is the priority number, if it isn't then you will have to add another variable to the structure that is the priority of that node. I didn't attempt to compile or test this, so use it at your own risk :S

{
liData *newItem = new liData;
newItem->PrintItem.jobNo = theID;
// find the insertion poit of the new node
liData *prev = NULL;
liData *temp = NULL;
{
// is new node's priority less than current node pointer's priority?
if(newItem->PrintItem.jobNo <  temp->PrintItem.jobNo)
{
if(prev == NULL)
{
newItem->ptrNext = temp;
break;
}
else
{
// add new node somewhere in the middle of the list
newItem->ptrNext = temp;
prev->ptrNext = newItem;
break;
}
prev = temp;
}
// if it gets to here then all the nodes in the list have the same
// priority as the new node.  So just add the new node to the