Guest User

Untitled

a guest
Apr 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include <stdlib.h>                                          
  2.                                                              
  3. typedef struct  s_chaine                                      
  4. {                                                            
  5.   int                   data;                                
  6.   struct s_chaine       *next;                                
  7.   struct s_chaine       *prev;                                
  8. }               t_chaine;                                    
  9.                                                              
  10. t_chaine        *add_to_end_list(t_chaine *foo, int data)    
  11. {                                                            
  12.   t_chaine      *new;                                        
  13.   t_chaine      *tmp;                                        
  14.                                                              
  15.   new = malloc(sizeof(*new));                                
  16.   new->data = data;                                          
  17.   new->next = NULL;                                          
  18.   new->prev = NULL;                                          
  19.   if (!foo)                                                  
  20.     return (new);                                            
  21.   tmp = foo;                                                  
  22.   while (tmp->next)                                          
  23.     tmp = tmp->next;                                          
  24.   tmp->next = new;                                            
  25.   new->prev = tmp;                                            
  26.   return (foo);                                              
  27. }                                                            
  28.                                                              
  29. int     main(void)                                            
  30. {                                                            
  31.   t_chaine      *my_chaine;                                  
  32.                                                              
  33.   my_chaine = NULL;                                          
  34.   my_chaine = add_to_end_list(my_chaine, 7);                  
  35.   my_chaine = add_to_end_list(my_chaine, 8);                  
  36.   my_chaine = add_to_end_list(my_chaine, 9);                  
  37.   while (my_chaine->next)                                    
  38.   {                                                          
  39.     printf("%d\n", my_chaine->data);                          
  40.     my_chaine = my_chaine->next;                              
  41.   }                                                          
  42.                                                              
  43.   my_chaine = my_chaine->next;                                
  44.   return (0);                                                
  45. }
Add Comment
Please, Sign In to add comment