How do I Sort Nodes to show all of the nodes that are sorted.

This is the code I have. It works but it only shows the first node. The other nodes are not displaying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void ShoppingList::sortNode(char Name[], double Price, int Priority)
{
	ListNode *nodePtr;
	nodePtr = head;

	for (bool didSwap = true;
		didSwap;)
	{
		didSwap = false;
		for (head = nodePtr;
			head->next != NULL;
			head = head->next)
		{
			if (head->priority > head->next->priority)
			{
				nodePtr->priority = head->priority;
				head->priority = head->next->priority;
				head->next->priority = nodePtr->priority;
				didSwap = true;
			}
		}
	}
}
Last edited on
Where do you ever output anything?
I think you shouldn't modify head.
Topic archived. No new replies allowed.