typedef struct node {
int x;
struct node *next;
struct node **head;
} node;
Considering this struct, I've implemented a push function:
node *push(node *nodo, node *top) {
nodo->next = top;
top = nodo;
nodo->head = ⊤
return top;
}
so that every node is aware of who is the current head list. But I have some problems when I have to delete the head of the list:
node *delete(node *top, int x) {
if (top->x == x)
return pop(top);
else
return *other function*;
}
node *pop(node *top) {
node *tmp = top;
top = tmp->next;
free(tmp);
return top;
}
When printing head content, this will give me segmentation fault:
void print(node *top) {
node *tmp = top;
printf("List:\n");
while (tmp != NULL) {
printf("%d\n", (*((tmp)->head))->x);
tmp = tmp->next;
}
printf("\nEnd\n");
}