When Trying to add a Student to the end of my List it comes out to be in the wrong alphabetical order. I have tried changing the add to end part of my function but can't seem to see what's wrong.
This is the way I add to end
Student *prvPtr= headStudentList;
for(Student *curPtr = headStudentList->next; curPtr != NULL; curPtr = curPtr->next)
{
if (curPtr->next==NULL){
curPtr->next= newPtr; //newPtr
return headStudentList;
}
if(strcmp(curPtr->lastName,last)<0 ){ //change from first
if(strcmp(curPtr->firstName,first)<0 )
{
newPtr->next=curPtr->next;
curPtr->next =newPtr; //curPtr->next =newPtr
return headStudentList; //headStudentList
}
}
}
This is what is inside of the structs
typedef struct _grade {
char name[4];
double value;
struct _grade *next;} Grade;
////////////////////////////////////////////////////////////////////////////////////////
typedef struct _student {
char *lastName;
char *firstName;
Grade *headGradeList;
struct _student *next;} Student;