-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstadd_front.c
More file actions
51 lines (40 loc) · 832 Bytes
/
Copy pathft_lstadd_front.c
File metadata and controls
51 lines (40 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
This function allows us to add a new element to the beginning of a given list.
It takes in both the new element and the existing list as inputs.
*/
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (lst == NULL || new == NULL)
return ;
new->next = *lst;
*lst = new;
}
/*
#include <stdio.h>
void print_list(t_list *lst)
{
while (lst)
{
printf("%p -> ", (void *)lst);
printf("%d\n", *(int *)(lst->content));
lst = lst->next;
}
printf("NULL\n");
}
int main(void)
{
int value1 = 42;
int value2 = 99;
t_list *lst = NULL;
t_list *node1 = ft_lstnew(&value1);
t_list *node2 = ft_lstnew(&value2);
ft_lstadd_front(&lst, node2);
ft_lstadd_front(&lst, node1);
printf("Linked List after adding elements to the front:\n");
print_list(lst);
free(node1);
free(node2);
return (0);
}
*/