Как создать указатель на голову в односвязном списке в си?
typedef struct t_list{
int hour;
int minute;
struct t_list *next;
}t_list;
t_list *create_node(int set_hour, int set_minute){
t_list *node=(t_list *)malloc(sizeof(t_list));
node->hour=set_hour;
node->minute=set_minute;
node->next=NULL;
return node;
}
void push_front(t_list **list, int set_hour,int set_minute){
t_list *new_element=create_node(set_hour, set_minute);
new_element -> next = *list;
*list=new_element;
}
Как добавить указатель на голову списка?
Ответы (1 шт):
Автор решения: Anton Shchyrov
→ Ссылка
Т.к. вы функцией push_front добавляете элемент в начало списка, то первый параметр у вас всегда будет указателем на голову
void push_front(t_list **list, int set_hour,int set_minute){
t_list *new_element=create_node(set_hour, set_minute);
new_element -> next = *list;
*list=new_element;
}
t_list *head = NULL;
push_front(&head, 1, 2);
push_front(&head, 3, 4);
push_front(&head, 5, 6);