Dynamic Linked Lists and File Manipulation/assign5.c
void addStudent(StudentInfoPtr *head, StudentInfoPtr student) {
    
    StudentInfoPtr previousStudentInfoPtr = NULL;
    StudentInfoPtr currentStudentInfoPtr = *head;
    
    StudentInfoPtr newStudentInfoPtr = student;    

    //Loops through the list to find suitable node to insert to
    while (currentStudentInfoPtr != NULL && 
            strtol(newStudentInfoPtr->studentId, NULL, 10) > strtol(currentStudentInfoPtr->studentId, NULL, 10)) {
        previousStudentInfoPtr = currentStudentInfoPtr;
        currentStudentInfoPtr = (StudentInfoPtr) currentStudentInfoPtr->next;
    }  
    
    if (previousStudentInfoPtr == NULL) {
        newStudentInfoPtr->next = *head;
        *head = newStudentInfoPtr;
    }
    else { 
        previousStudentInfoPtr->next = newStudentInfoPtr;
        newStudentInfoPtr->next = currentStudentInfoPtr;
    }
}
/*
    addStudent: adds a student to the linked list
    input: the beginning of the linked list
*/
adds a student to the linked list
input: the beginning of the linked list
adds a student to the linked list input : the beginning of the linked list
void addStudent(StudentInfoPtr *head, StudentInfoPtr student) {
    StudentInfoPtr previousStudentInfoPtr = NULL;
    StudentInfoPtr currentStudentInfoPtr = *head;
    StudentInfoPtr newStudentInfoPtr = student;    
    while (currentStudentInfoPtr != NULL && 
            strtol(newStudentInfoPtr->studentId, NULL, 10) > strtol(currentStudentInfoPtr->studentId, NULL, 10)) {
        previousStudentInfoPtr = currentStudentInfoPtr;
        currentStudentInfoPtr = (StudentInfoPtr) currentStudentInfoPtr->next;
    }  
    if (previousStudentInfoPtr == NULL) {
        newStudentInfoPtr->next = *head;
        *head = newStudentInfoPtr;
    }
    else { 
        previousStudentInfoPtr->next = newStudentInfoPtr;
        newStudentInfoPtr->next = currentStudentInfoPtr;
    }
}
void addStudent ( StudentInfoPtr * head , StudentInfoPtr student ) { StudentInfoPtr previousStudentInfoPtr = NULL ; StudentInfoPtr currentStudentInfoPtr = * head ; StudentInfoPtr newStudentInfoPtr = student ; while ( currentStudentInfoPtr != NULL && strtol ( newStudentInfoPtr -> studentId , NULL , 10 ) > strtol ( currentStudentInfoPtr -> studentId , NULL , 10 ) ) { previousStudentInfoPtr = currentStudentInfoPtr ; currentStudentInfoPtr = ( StudentInfoPtr ) currentStudentInfoPtr -> next ; } if ( previousStudentInfoPtr == NULL ) { newStudentInfoPtr -> next = * head ; * head = newStudentInfoPtr ; } else { previousStudentInfoPtr -> next = newStudentInfoPtr ; newStudentInfoPtr -> next = currentStudentInfoPtr ; } }
addStudent: adds a student to the linked list
input: the beginning of the linked list
addStudent : adds a student to the linked list input : the beginning of the linked list
//Loops through the list to find suitable node to insert to