title: Multiplication of digits in two linked lists
body: <p>I am trying to multiply digits that are stored in two singly linked lists. However, my algorithm has turned to be getting very complex. I am doing the multiplication the way we did in elementary schools. Getting the value of one of the lists and multiplying in to each value of the other list till we cover all numbers. The problem is tat I have to add these numbers up at the end to get the final result of the multiplication, and this is where I get in to trouble. I have to find a way to be able to multiply any number of elements in to each other and be able to add the results up at the end. So far my code is like this</p>
  
  <pre><code>public SingleyLinkedList Multiply(SingleyLinkedList list1, 
                                    SingleyLinkedList list2)
          {
          SingleyLinkedList multiplyList = new SingleyLinkedList();
          SingleyLinkedList tempList1 = new SingleyLinkedList();
          SingleyLinkedList tempList2 = new SingleyLinkedList();
  
          for (int j = 0; j &lt; list2.Size(); j++)
          {
              int carry = 0;
              int B = Convert.ToInt32(list2.GetValue(j));
  
              for (int k = 0; k &lt; list1.Size(); k++)
              {
  
                  int A = Convert.ToInt32(list1.GetValue(k));
  
                  if (k == list1.Size()-1)
                  {
                      int multiply = ((A * B) + carry);
                      multiplyList.InsertAtFront(multiply);
                      carry = 0;
                  }
                  if (k &lt; list1.Size()-1)
                  {
                      int multiply = ((A * B) + carry) % 10;
                      multiplyList.InsertAtFront(multiply);
                      carry = 0;
                  }
                  carry = (int)((A * B) / 10);
              }
          }
        //return multiplyList;
  
          for ( int t = 0 ; t &lt; list2.Size() ; t++)
          {
  
              for (int n = 0; n &lt; list1.Size(); n++)
              {
                  int val = Convert.ToInt32(multiplyList.GetValue(n));
                  tempList1.InsertAtFront(val);
              }
  
              // adding zero to take care of 10th                
              for (int m = 0; m &lt; list2.Size() - 1; m++)
              {
                  tempList1.InsertAtFront(0);
              }
  
          }
  
          return tempList1;`
  </code></pre>
  
  <p>After this stage, I have to pass my values to the Add method that I have created, which takes two linked lists as parameters and does the addition. I need to be able to do this process for as many numbers as I desire. 
  Any suggestion or if you know of any better way to do the multiplication at all?</p>