I wonder how to make 2 functions based of this code:
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node * next;
} node_t;
node_t* create_node(int val)
{
node_t * head = NULL;
head = malloc(sizeof(node_t));
if (head == NULL) {
return NULL;
}
head->val = val;
head->next = NULL;
}
void print_list(node_t * head)
{
node_t * current = head;
while (current != NULL) {
printf("%d\n", current->val);
current = current->next;
}
}
void insert_end(node_t * head, int val)
{
node_t * current = head;
while (current->next != NULL) {
current = current->next;
}
current->next = malloc(sizeof(node_t));
current->next->val = val;
current->next->next = NULL;
}
void insert_begin(node_t ** head, int val)
{
node_t * new_node;
new_node = malloc(sizeof(node_t));
new_node->val = val;
new_node->next = *head;
*head = new_node;
}
One function should remove an element with the given index, and the second one with the given value.
I'm new to the C language, and I don't really understand the syntax, that's why I would appreciate any kind of help.