title: How to sort linked list by date?
body: <p>We're suppose to make a scheduler with a title, some details, a date and a classified priority using a sorted linked lists.</p>
  
  <p>I managed to sort them by priority but first I have to sort them by date.
  Since the date I am using is a structure with an int month, int day, int year. I have trouble sorting all 3 at the same time. I can only figure out how to sort either per year or per day or per month.</p>
  
  <p>Here's my dummy code for sorting dates:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct D{
      int month;
      int day;
      int year;
  }DATE;
  
  typedef struct node_tag{
      DATE d;
      struct node_tag * next;
  }NODE;
  
  int main(){
      NODE *head = NULL;
      NODE *temp, *ptr, *print;
      int usr = 1;
      while(usr!=0){
      DATE date;
      scanf("%d", &amp;usr);
      printf("Enter date: ");
      scanf("%d %d %d", &amp;date.month, &amp;date.day, &amp;date.year);
      temp = (NODE *)malloc(sizeof(NODE));
      temp-&gt;d.month = date.month;
      temp-&gt;d.day = date.day;
      temp-&gt;d.year = date.year;
      temp-&gt;next = NULL;
  
      if(head == NULL || head-&gt;d.year &gt; temp-&gt;d.year){
          temp-&gt;next = head;
          head = temp;
      }
      else if(head == NULL || head-&gt;d.year == temp-&gt;d.year){
          if(head-&gt;d.month &gt; temp-&gt;d.month){
              temp-&gt;next = head;
              head = temp;
          }
  
      }
      else{
          ptr = head;
          while(ptr-&gt;next !=NULL &amp;&amp; ptr-&gt;next-&gt;d.year &lt; temp-&gt;d.year){
              ptr = ptr-&gt;next;
      }
  
      temp-&gt;next = ptr-&gt;next;
      ptr-&gt;next = temp;
  }
      }
      print = head;
      while(print!= NULL){ //prints the list
              printf("%d %d %d\n", print-&gt;d.month, print-&gt;d.day, print-&gt;d.year);
              print = print-&gt;next;
          }
  }
  </code></pre>
  
  <p>Can I get any tips and help?</p>