E
Emanuele Blanco
Hi there,
I just compiled a program that uses linked lists (needed it as an homework
for my Programming course at University). It works flawlessly, even if I
notice a thing. Here's my linked list declaration:
struct node {
float item;
struct node *next;
};
typedef struct node *list;
I need a function that removes a node in that list, without checking the
emptyness of the list. So here's my code:
void remove_key(list *lista, float key) {
list temp=*lista;
if (temp->item == key) {
*lista=temp->next;
free(temp);
}
else
remove_key((list *)(temp->next), key);
}
My question is: I needed the casting to list * to make the recursive call
work. I wasn't able to get it work using a syntax like
remove_key(*(temp->next), key). There's a proper syntax to point to a struct
member, or do I need the cast ? Compiling with gcc makes the incompatible
parameter type error.
Thanks in advance and sorry for my English.
I just compiled a program that uses linked lists (needed it as an homework
for my Programming course at University). It works flawlessly, even if I
notice a thing. Here's my linked list declaration:
struct node {
float item;
struct node *next;
};
typedef struct node *list;
I need a function that removes a node in that list, without checking the
emptyness of the list. So here's my code:
void remove_key(list *lista, float key) {
list temp=*lista;
if (temp->item == key) {
*lista=temp->next;
free(temp);
}
else
remove_key((list *)(temp->next), key);
}
My question is: I needed the casting to list * to make the recursive call
work. I wasn't able to get it work using a syntax like
remove_key(*(temp->next), key). There's a proper syntax to point to a struct
member, or do I need the cast ? Compiling with gcc makes the incompatible
parameter type error.
Thanks in advance and sorry for my English.