Please use code tags when posting code, preferably the language-specific version so we get syntax highlighting. It makes the code MUCH easier to read.
If you want the linked list to be ordered by last name, the convention is to put the record in the list where it belongs.
If the first record added is for "James Smith" then it is the only record. If we now want to add a record for "Bill Wilson", it should be added after "James Smith". If we then add a record for "Carol Fisher" if goes before "James Smith". Repeat as additional records are added and the list will always be sorted by last name.
So the code ends up looking something like:
// preinitialize the new record's next to null
newstudent -> next = null;
student_list * prev = null;
student_list * curr = head;
// while there are more records to look at on the list
while (curr != null)
{
// should the new record come before the 'current' record in the list?
if (strcmp(newstudent -> Last_Name, curr -> Last_Name) < 0)
{
newstudent -> next = curr;
break
}
prev = curr;
curr = prev -> next;
}
if (prev == null)
head = newstudent
else
prev -> next = newstudent