title: What is the best way to create/reverse a linked list?
body: <p>I'm a beginner at programming and I've learnt how to reverse a linked list.
  Below is the code I used to make a linked list with random values and reverse it. I was wondering what the best way to do this would be. Thanks for your suggestions! Have a great day!</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;time.h&gt;
  
  // node
  typedef struct node{
      int number;
      struct node *next;
  }node;
  
  // functions
  node *reversedList(node *head);
  void printList(node *head);
  node *create(int size);
  
  int main(void)
  {
      srand(time(0));
      // ........
  }
  
  node *reversedList(node *curr)
  {
      // a-&gt;b-&gt;c-&gt;d
      // d-&gt;c-&gt;b-&gt;a
      node *previous = NULL;
      while(curr-&gt;next != NULL)
      {
          node *curr_temp = curr-&gt;next;
          curr-&gt;next = previous;
          previous = curr;
          curr = curr_temp;
      }
      curr-&gt;next = previous;
      return curr;
  }
  
  void printList(node *head)
  {
      if (head == NULL)
          return;
      printf(&quot;%d &quot;,head-&gt;number);
      printList(head-&gt;next);
  }
  
  node *create(int size)
  {
      if(size == 0)
          return NULL;
      node *n = malloc(sizeof(node));
      n-&gt;number = rand() % 10;
      n-&gt;next = create(size - 1);
      return n;   
  }
  </code></pre>