title: Doubly linked list maintain sorted list
body: <p>How can I maintain the list sorted without a sort function. When I add node I want to maintain the list sorted. 
  Also when removing a node.</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;cstdlib&gt;
      #include &lt;string&gt;
      using namespace std;
  
  
  struct Node
  {
   //node declare
    double value;
    Node *next;
    Node *prev;
    Node(double y)
    {
        value = y;
        next = prev = NULL;
    }
  };
  
  class DLinkedList
  {
    Node *front;
    Node *back;
    public:
    DLinkedList()
    {  
                 front = NULL; back = NULL; 
    }
    //declare function
    void NodeFront(double x);
    void NodeBack(double x);
    void dispForward();
    void dispReverse();
  }; 
  void DLinkedList::NodeFront(double x)
    {
          Node *n = new Node(x);
  
          if( front == NULL)
          {
              front = n;
              back = n;
          }
          else
          {
              front-&gt;prev = n;
              n-&gt;next = front;
              front = n;}
  
    }
    void DLinkedList::NodeBack(double x)
    {
          Node *n = new Node(x);
          if( back == NULL)
          {
              front = n;
              back = n;
          }
          else
          {
              back-&gt;next = n;
              n-&gt;prev = back;
              back = n;
  
          }
  
  }
   //forward nodes
    void DLinkedList::dispForward()
    {
        Node *temp = front;
        cout &lt;&lt; "forward order:" &lt;&lt; endl;
        while(temp != NULL)
        {
           cout &lt;&lt; temp-&gt;value &lt;&lt; " " ;
           cout&lt;&lt;endl;
           temp = temp-&gt;next;
        }
    }
    //reverse list
    void DLinkedList::dispReverse()
    {
        Node *temp = back;
        cout &lt;&lt; "reverse order :" &lt;&lt; endl;
        while(temp != NULL)
        {
           cout &lt;&lt; temp-&gt;value &lt;&lt; " " ;
           cout&lt;&lt;endl;
           temp = temp-&gt;prev;
        }
    }
  
  int main()
  {
      DLinkedList *list = new DLinkedList();
      //front of the list
      list-&gt;NodeFront(45.0);
      list-&gt;NodeFront(49.0);
      list-&gt;NodeFront(42.0);
      list-&gt;NodeFront(48.0);
      list-&gt;NodeFront(48.0);
      list-&gt;NodeFront(52.0);
      list-&gt;NodeFront(12.0);
      list-&gt;NodeFront(100.0);
  
      list-&gt;dispForward();
      list-&gt;dispReverse();
      cin.get();
      return 0;
  }
  </code></pre>