title: Recursive Ascending and Recursive Descending Order Functions for a Linked List
body: <p>This is a homework assignment, I've written most of the code already, the only thing I can't figure out is that I have to have a recursive function to sort the linked list in ascending order, and a recursive function to sort the linked list in descending order. I'm pretty lost.</p>
  
  <p>Here is my entire code.</p>
  
  <pre><code>using namespace std;
  
  struct ListNode;
  typedef ListNode* ListPtr;
  
  struct ListNode
  {
      int number;
      ListPtr next;
  
      ListNode(int value, ListPtr ptr = NULL)
      {
          number = value;
          next = ptr;
      }
  };
  
  char Menu();
  void Add(ListPtr &amp;, int);
  void Delete(ListPtr &amp;, int);
  void Ascend(ListPtr &amp;);
  void Descend(ListPtr &amp;);
  void Print(ListPtr &amp;);
  void DeleteList(ListPtr &amp;);
  
  int main()
  {
      ListPtr head = NULL;
      char answer;
      int input;
  
      answer = Menu();
      while(answer != 'Q')
      {
          if(answer == 'A')
          {
              cout &lt;&lt; "Please enter in an integer: ";
              cin &gt;&gt; input;
              Add(head, input);
          }
          else if(answer == 'D')
          {
              cin &gt;&gt; input;
              Delete(head, input);
          }
          else if(answer == 'P')
          {
              Ascend(head);
          }
          else if(answer == 'O')
          {
              Descend(head);
          }
          else if(answer == 'N')
          {
              Print(head);
          }
          else
          {
              cout &lt;&lt; "Incorrect input, please try again.\n";
          }
  
          answer = Menu();
      }
  
      DeleteList(head);
      return 0;
  }
  
  char Menu()
  {
      char uinput;
  
      cout &lt;&lt; "Please enter in one of the following:\n";
      cout &lt;&lt; "A: Add an item to the end of the list.\n";
      cout &lt;&lt; "D: Delete an item from the list.\n";
      cout &lt;&lt; "P: Print the list in ascending order.\n";
      cout &lt;&lt; "O: Print the list in descending order.\n";
      cout &lt;&lt; "N: Display the number of items in the list.\n";
      cout &lt;&lt; "Q: Quit.\n";
  
      return toupper(uinput);
  }
  
  void Add(ListPtr &amp;start, int item)
  {
      if(start-&gt;number &gt; item || start == NULL)
          start = new ListNode(item, start);
      else
          Add(start-&gt;next, item);
  }
  
  void Delete(ListPtr &amp;start, int item)
  {
      if(start != NULL)
      {
          if(start-&gt;number == item)
              ListPtr cur = start;
          start = start-&gt;next;
          delete cur;
      }
      else
      {
          Delete(start-&gt;next, item);
      }
  }
  
  void Ascend(ListPtr &amp;start)
  {
  
  } 
  
  void Descend(ListPtr &amp;start)
  {
  
  }
  
  void Print(ListPtr &amp;start)
  {
      ListPtr cur = start;
      int count = 0;
  
      if(cur == NULL)
      {
          cout &lt;&lt; "The list is empty.\n";
      }
      else
      {
          if(cur != NULL)
          {
              if(count % 10 == 0)
                  cout &lt;&lt; endl;
              cout &lt;&lt; setw(5) &lt;&lt; cur-&gt;number;
              cur = cur-&gt;next;
              count++;
          }
      }
      cout &lt;&lt; endl;
  }
  
  
  void DeleteList(ListPtr &amp;start)
  {
      if(start != NULL)
      {
          DeleteList(start-&gt;next);
          cout &lt;&lt; "Deleting item " &lt;&lt; start-&gt;number &lt;&lt; endl;
          delete start;
      }
  }
  </code></pre>