I've created a program that would insert a node into a linked list based on alphabetical order (A-Z). I'm able to do it, however, I'm not able to insert at the front of the linked list. We can assume that the list is never initially empty. Any help? Here is my code with the relevant structs. The problem is where // Inserting at the front of the list
typedef struct fileNode {
char *tokenName; // hi
double token; // 0.5
struct fileNode *next;
} fileNode;
typedef struct fileStruct {
char *name; // a.txt
int numberOfTokens; // 4
fileNode *tokenLL;
struct fileStruct *next;
} fileStruct;
void insertLL(struct fileNode *list, char *token){
struct fileNode *ptr = list;
struct fileNode *prev = NULL;
struct fileNode *newNode = malloc(sizeof(struct fileNode));
newNode->tokenName = token;
newNode->token = 1;
bool inserted = false;
while (ptr != NULL && inserted == false) {
if (strcmp(ptr->tokenName, token) > 0){
count++;
if (prev == NULL){ // Inserting at the front of the list
newNode->next = ptr;
ptr = newNode;
list = newNode;
inserted = true;
return;
}
else {
prev->next = newNode;
newNode->next = ptr;
inserted = true;
}
} // end of if
prev = ptr;
ptr = ptr->next;
} // end of while
if (!inserted){
prev->next = newNode;
} // adding to the end of the list
}