title: Bidirectional list
body: <p>The following code calculates the sum of the elements of the unidirectional list items greater than 3 and smaller than 8 and the result of the sum is changed the beginning of the list.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  struct List 
  {
      int num;
      List* nItem;
  };
  
  int Input()
  {
      int number;
      cout &lt;&lt; "Enter the number: "; cin &gt;&gt; number;
      return number;
  }
  
  void MakeList(List **head, int n)
  {
      if (n &gt; 0) {
          *head = new List;
          (*head)-&gt;num = Input();
          (*head)-&gt;nItem = NULL;
          MakeList(&amp;(*head)-&gt;nItem, n - 1);
      }
  }
  
  void Print(List* head)
  {
  
      if (head != NULL)  {
          cout &lt;&lt; head-&gt;num &lt;&lt; " ";
          Print(head-&gt;nItem);
      }
  }
  
  List* Add_start(List* head, int index, int elm)
  {
      List* p = new List;
      p-&gt;num = elm;
      p-&gt;nItem = NULL;
  
      if (head == NULL)  {
          head = p;
      }
      else  {
          List* current = head;
          for (int i = 0; (i &lt; index - 1) &amp;&amp; (current-&gt;nItem != NULL); i++) 
          {
              current = current-&gt;nItem;
          }
          if (index == 0)  
          {
              p-&gt;nItem = head;
              head = p;
          }
          else  {
              if (current-&gt;nItem != NULL)  {
                  p-&gt;nItem = current-&gt;nItem;
              }
              current-&gt;nItem = p;
          }
      }
  
      return head;
  }
  
  int Sum(List* head)
  {
      int sum = 0;
      List* p = head;
      while(p) {
          if ((p-&gt;num &gt; 3) &amp;&amp; (p-&gt;num &lt; 8))
              sum += p-&gt;num;
          p = p-&gt;nItem;
      }
  
      return sum;
  }
  
  void DeleteList(List* head)
  {
      if (head != NULL) {
          DeleteList(head-&gt;nItem);
          delete head;
      }
  }
  
  int main()
  {
      int n = 10;
      List* head = NULL;
  
      cout &lt;&lt; "Enter 10 number to the list\n" &lt;&lt; endl;
      MakeList(&amp;head, n);
      int sum = Sum(head);
      head = Add_start(head, 0, sum);
  
      cout &lt;&lt; "\nList: ";
      Print(head);
      cout &lt;&lt; endl;
  
      DeleteList(head);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>How can I do the same operation with a bidirectional list?</p>