Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct List{
  5.   struct list *next;
  6.   char *name;
  7. }list;
  8.  
  9. list *start = NULL;
  10. list *end = NULL;
  11.  
  12. list *liste = NULL;
  13.  
  14. int count_nodes=0;
  15.  
  16. list *add(list *liste,char *data){
  17.  
  18.   list *neu = malloc(sizeof(list));
  19.  
  20.   if(liste==NULL){
  21.  
  22.     liste=malloc(sizeof(list));
  23.    
  24.     start=neu;
  25.     end=neu;
  26.     liste=start;
  27.   }
  28.  
  29.   else{
  30.     end->next=neu;
  31.     end=neu;
  32.   }
  33.  
  34.   neu->name=data;
  35.   neu->next=NULL;
  36.   count_nodes++;
  37.  
  38.   free(neu);
  39.  
  40.   return liste;
  41. }
  42.  
  43. /*
  44. list *rm(list *liste,char *name){
  45.   list *del = malloc(sizeof(list));
  46.   del=start;
  47.  
  48.   while(del!=NULL){
  49.     if(del->name==name){
  50.       printf("%s\n",del->name);
  51.     }
  52.     del=del->next;
  53.   }
  54.  
  55.   free(del);
  56.   }*/
  57.  
  58.  
  59. int main(int argc, char *argv[]){
  60.  
  61.   char n1 [] = "rob";
  62.   char n2 [] = "til";
  63.   liste=add(liste,n1);
  64.   liste=add(liste,n2);
  65.  
  66.   /*
  67.   liste=rm(liste,n1);
  68.   */
  69.  
  70.   int i;
  71.   for(i=0;i<count_nodes;i++){
  72.     printf("%s\n",start->name);
  73.     start=start->next;
  74.   }
  75.  
  76.   return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement