Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef
  6. struct node{
  7. int data;
  8. struct node *next;
  9. }
  10. int_list;
  11.  
  12. int_list *create_list(){
  13.  
  14. return NULL;
  15. }
  16.  
  17.  
  18.  
  19. int pushback(int_list **head,int d){
  20.  
  21.  
  22. int_list *newNode = (int_list*)malloc(sizeof(int_list));
  23.  
  24. newNode->data = d;
  25. newNode->next = NULL;
  26.  
  27. if(*head== NULL){
  28. *head = newNode;
  29.  
  30. }
  31.  
  32. else
  33. {
  34. int_list *current = *head;
  35. while (current->next != NULL) {
  36. current = current->next;
  37. }
  38. current->next = newNode;
  39.  
  40.  
  41. }
  42. return 0;
  43. }
  44. void print_list(int_list *list)
  45. {
  46. if (list==NULL);
  47. else {
  48. printf("%d ", list->data);
  49. print_list(list->next);
  50. }
  51. }
  52. int main (int argc, char *argv[]){
  53. int_list *lista = create_list();
  54.  
  55. if (argc == 4){
  56.  
  57. int a = atoi(argv[1]);
  58. int b = atoi(argv[2]);
  59. int c = atoi(argv[3]) ;
  60.  
  61. pushback(&lista, a);
  62. pushback(&lista, b);
  63. pushback(&lista, c);
  64.  
  65. print_list(lista);
  66. printf("\n");
  67. }
  68. else {
  69.  
  70. printf("neeeeej");
  71. }
  72.  
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement