daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. node *createLinkedList(int n) {
  2.     node *head = NULL;
  3.     node *back = NULL;
  4.     node *temp;
  5.  
  6.     for (int i = 0; i < n; i++) {
  7.         temp = (node *) malloc(sizeof(node));
  8.  
  9.         printf("\nEnter the data for node number: %d", i + 1);
  10.         scanf("%d", &temp->data);
  11.  
  12.         temp->next = NULL;
  13.  
  14.         if (head == NULL) {
  15.             head = back = temp;
  16.  
  17.             printf("\n IF loop");
  18.         } else {
  19.             back->next = temp;
  20.             back = temp;
  21.         }
  22.  
  23.         printf("\n ending loop");
  24.         //free(temp);
  25.     }
  26.  
  27.     return head;
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top