title: C++ Doubly linked list adding node in alphabetical order and value
body: <p>My task is a create doubly linked list and sort them according to their data, if new written node's data is equal to the one of the nodes' data in my doubly linked list, i should sort them in a alphabetical order but I am stuck in the function <code>strcmp(temp-&gt;name, newnode-&gt;name)</code>,
  For example, I am trying to check if these values entered in order</p>
  <ol>
  <li>Christian 250</li>
  <li>Tom 200</li>
  <li>Alex 250</li>
  </ol>
  <p>My sorted doubly linked list give the output as</p>
  <ol>
  <li>Alex 250</li>
  <li>Christian 250</li>
  <li>Tom 200</li>
  </ol>
  <p>Here is example of my code</p>
  <pre><code>   struct node {
      int data;
      string name;
      node* left;
      node* right;
  
      node(int i = 0, string s = &quot;&quot;, node* l = nullptr, node* r = nullptr) : data(i), name(s), left(l), right(r) {}
  };
  
  struct node* head = NULL;
  struct node* tail = NULL;
  </code></pre>
  <p>at the top of the program</p>
  <pre><code>void insert(int newdata, string name)  // Used for insertion at the end of the linked list and make 
  {                                      // the connection for each of the node
      node* newnode = new node();
      node* nodehead = head;
      newnode-&gt;data = newdata;
      newnode-&gt;name = name;
      newnode-&gt;right = NULL;
  
      if( head == NULL)
      {
          newnode -&gt; left = NULL;
          head = tail = newnode;
      }
      else 
      {
          while (nodehead-&gt;right != NULL)
          {
              nodehead = nodehead-&gt;right;     
          }
              nodehead-&gt;right = newnode; // make the connection for each of them
              newnode-&gt;left = nodehead;
              tail = newnode; // and newly created node is our tail
  
              sorting(newnode); // then go the function to sort them 
      }
     
      cout &lt;&lt; &quot;New node is added &quot; &lt;&lt; newnode-&gt;name &lt;&lt; &quot; &quot; &lt;&lt; newnode-&gt;data &lt;&lt; endl;
  }
  </code></pre>
  <p>then sort them based on their comparison of their data and if they are equal i should check based on their alphabetical order</p>
  <pre><code> void sorting( node *  &amp;newnode) // ı call sorting function in the insertion function
      {
          node* temp = head;
          node* temp2 = newnode;
      
          int numtemp;
      
          while (temp != nullptr)
          {
              node* temp2 = temp-&gt;right;
              while (temp2 != nullptr)
              {       
                  if (temp2-&gt;data &gt; temp-&gt;data) // comparison of their data if newnode's data is larger 
                  {
                      string strtemp = &quot;&quot;;
                      numtemp = temp-&gt;data; // Change their number
                      temp-&gt;data = temp2-&gt;data;
                      temp2-&gt;data = numtemp;
      
                      strtemp = temp-&gt;name; // Change their name
                      temp-&gt;name = temp2-&gt;name;
                      temp2-&gt;name = strtemp;
                  }
                  else if (temp2-&gt;data = temp-&gt;data) // if newly data is equal to linked list data
                  {
                      int ret;
                      ret =  strcmp(temp2-&gt;name, temp-&gt;name); // i tried to check their string comparison but it did not work
                  }
                  temp2 = temp2-&gt;right;
              }
              temp = temp-&gt;right;
          }        
      }
  </code></pre>