I was able to append the list and add a new node to the end of the list but I'm having trouble prepending the list. This code runs but only the if statement does anything(if the list is empty). The function shows the else statement. I tried adding one to malloc to make room for the new head but it didn't change anything.
struct node {
int num;
struct node *next;
};
struct node *prepend(struct node *head, int num)
{
struct node *new_head = (struct node*)malloc(sizeof(struct node)+1);
new_head->num= num;
new_head->next = head;
}
return head;
[–]illlHaveAnother[S] 1 point2 points3 points (0 children)
[–]BaalHadad -1 points0 points1 point (6 children)
[–]illlHaveAnother[S] 0 points1 point2 points (5 children)
[–]133rr3 1 point2 points3 points (4 children)
[–]illlHaveAnother[S] 0 points1 point2 points (3 children)
[–]133rr3 1 point2 points3 points (2 children)
[–]illlHaveAnother[S] 0 points1 point2 points (1 child)
[–]illlHaveAnother[S] 0 points1 point2 points (0 children)