Sorting linked list in descending order

I have a function that inserts 1000 lines into a linked list, each line gets inserted at end. But I need modify it so it will organize the linked list in descending order based on a number in the very front of the line. There is a 4-6 digit number in front followed by a tab and then a string. But the problem is, is I have to read each line at a string since it is a mix of numbers and letters and so it sorts correctly if the number was a word so not all the numbers end up in the right place and I do not know what to do in order to sort it correctly... Any help would be greatly appreciated!
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
38
void Term :: sorting ()
{
	node * temphead = start;
	//ListNode * tempnode = NULL;
	string temproll;
	string tempname;
	int counter = 0;
	while (temphead)
	{
		temphead = temphead->next;
		counter++;
	}
	temphead = start -> next;
	
	for (int j=0; j<counter; j++)
	{
		while (temphead->next)  //iterate through list until next is null
		{
			if (temphead->text < temphead->next->text)
			{
				/*tempnode = temphead;
				temphead = temphead->next;
				temphead->next = tempnode;*/
				temproll = temphead->text;
				temphead->text = temphead->next->text;
				temphead->next->text = temproll;

				tempname = temphead->name;
				temphead->name = temphead->next->name;
				temphead->next->name = tempname;
				temphead = temphead->next;//increment node
			}
			else 
				temphead = temphead->next;//increment node
		}	
		temphead = start;//reset temphead
	}
}


Last edited on
Topic archived. No new replies allowed.