inserting issues

Cannot get this code working right, any help is greatly appreciated. I've got it printing all of the values, however it's inputting the nodes incorrectly.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
void insertTokens(listNode*& head, char* tokens[])
{

 // Creates new node and inserts tokenized values

 cout << "Inserting: " << tokens[0];
 cout << " " << tokens[1];
 cout << " " << tokens[2] << endl;

 newNode = new listNode;
 newNode-> lastName = tokens[0];  // Node value lastName
 newNode-> firstName = tokens[1]; // Node value firstName
 newNode-> age = tokens[2];       // Node value age
 newNode-> next = NULL;

 listNode* current = head; // set traversal pointer

 if(!head) // If no head node, create one
  {
   head = newNode;
   newNode-> next = NULL;
   cout << "Head Node" << endl;
  }
 
 else if(current-> lastName > newNode-> lastName)
  {
   newNode-> next = current;
   head = newNode;
   cout << "New Head Node" << endl;
  }
 
 else
  {

if(current-> next == NULL) // Adds newNode to end of list
 {
  newNode-> next = current-> next;
  current-> next = newNode;
  cout << "eol" << endl;
 }


    cout << "start while" << endl;
 while(current-> next-> lastName < newNode-> lastName) // Traverse the list
   {
	  current = current-> next;
	  cout << "1" << endl;

	if(current-> lastName == newNode-> lastName) // Compare lastName
	 {
	  /*if(current-> firstName == newNode-> firstName) // Compare firstName
	   {
	    
	   }
	  else //if(current-> firstName < newNode-> firstName)
	   {
	    newNode-> next = current-> next;
	    current-> next = newNode;
	   }*/
		 cout << "2" << endl;
		 reportDuplicate();
     }	
	 
	else if(current-> lastName < newNode-> lastName) // Insert node by last name
	 {
	  newNode-> next = current-> next;
	  current-> next = newNode;
	 }

	cout << "3" << endl;

   }//end while(traversal)

 cout << "end while" << endl;
 }//end else 


This is the output. I am not sure why its printing in reverse order after a certain point.

C:\Users\Zero>g++ LinkListProject.cpp

C:\Users\Zero>a.exe names.txt

Input File is open...

Inserting: 3 3 3
Head Node
Inserting: 2 2 2
New Head Node
Inserting: 1 1 1
New Head Node
Inserting: 4 4 4
start while
1
3
end while
Inserting: 5 5 5
start while
1
3
end while
Inserting: 6 6 6
start while
1
3
end while
Inserting: 7 7 7
start while
1
3
end while
Inserting: 8 8 8
start while
1
3
end while
Inserting: 9 9 9
start while
1
3
end while

Incomplete Record:

Displaying List
--------------------------------------

1 1 1
2 2 2
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
The input file contains this exactly:

3 3 3
2 2 2
1 1 1
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
Topic archived. No new replies allowed.