I'm trying to insert a node at the end of the linked list but for some reason my print function tells me that the list is empty.
Struct:
struct node{
int data;
struct nodeList *next;
};
Here is my addNode function
struct node* addNode(struct node* List, int n){
struct node* newNode = (struct node*)malloc(sizeof(struct node));
struct node* temp = (struct node*)malloc(sizeof(struct node));
newNode->data = n;
newNode->next= NULL;
if(List == NULL){
List = newNode;
return List;
}
temp = List;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = newNode;
return List;
}
I appreciate any help!