Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- typedef struct s_chaine
- {
- int data;
- struct s_chaine *next;
- struct s_chaine *prev;
- } t_chaine;
- t_chaine *add_to_end_list(t_chaine *foo, int data)
- {
- t_chaine *new;
- t_chaine *tmp;
- new = malloc(sizeof(*new));
- new->data = data;
- new->next = NULL;
- new->prev = NULL;
- if (!foo)
- return (new);
- tmp = foo;
- while (tmp->next)
- tmp = tmp->next;
- tmp->next = new;
- new->prev = tmp;
- return (foo);
- }
- int main(void)
- {
- t_chaine *my_chaine;
- my_chaine = NULL;
- my_chaine = add_to_end_list(my_chaine, 7);
- my_chaine = add_to_end_list(my_chaine, 8);
- my_chaine = add_to_end_list(my_chaine, 9);
- while (my_chaine->next)
- {
- printf("%d\n", my_chaine->data);
- my_chaine = my_chaine->next;
- }
- my_chaine = my_chaine->next;
- return (0);
- }
Add Comment
Please, Sign In to add comment