Queue::QueueNode* Queue::getPointer(int nodeNo)
{
QueueNode *cur = frontPtr;
for(int i = 1; i < nodeNo; i++)
cur=cur->next;
return cur;
}
void Queue::insertionsort()
{
int counter = 2;
for(QueueNode* cur = frontPtr->next; cur != NULL; cur=cur->next)
{
int p = cur->priority;
QueueNode *sort = cur;
for(int i=counter;i>1;i--)
{
QueueNode *prev=getPointer(counter-1);
if(prev->priority < p)
{
QueueNode *slot = sort;
slot->next=prev->next;
slot = prev;
sort->next = slot;
}
}
counter++;
}
}
i was trying to do about insertion sort in queue.
i can succesful run the program but it stuck when i call insertion
fuction. It was not runtime error, it juz stuck at the program, when i press enter it juz wont continue run.
What happens when you put everything between 'for(QueueNode* cur = frontPtr->next; cur != NULL; cur=cur->next)' and the closing '}' in comments, does it still stop functioning? If yes your for loop is incorrect, if it doesn't and seems to work, go to the next for loop.
then the program can run, but i duno which 1 wrong about this code.
these codes should shift the node to the right if the priority is higher, then insert the higher priority back to the front.
but i duno how to code it.