Linked List sorting lockup

What I'm trying to do is sort a number of nodes of a linked list by a double value in the structure. However the program keeps crashing at the end of the sort function.

Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void scholarshipList::sortedRecords()
{
	scholarshipNode *newHead, *currentNode, *previousNode, *lowestNode, *lowestPreviousNode;
	newHead = head;
	head = NULL;
	double lowestAmount;
	
	while (newHead != NULL)  //While there is still a node under the head.
	{
		currentNode = newHead->next;
		lowestAmount = currentNode->amount;
		lowestNode = currentNode;
		previousNode = newHead;
		
		while (currentNode->next)  //While there is still a node under the current node.
		{
			previousNode = currentNode;
			currentNode = currentNode->next;
			
			if(currentNode->amount < lowestAmount)
			{
				lowestPreviousNode = previousNode;
				lowestAmount = currentNode->amount;
				lowestNode = currentNode;
			}
		}
		if (currentNode == newHead)
		{
			newHead = NULL;
		}
		lowestPreviousNode->next = lowestNode->next;
		lowestNode->next = head->next;   // The problem is one
		head->next = lowestNode;         // of these two lines I believe
	}
	
	displayAll();
}


Any help on getting this fixed would be much appreciated.
Topic archived. No new replies allowed.