c++ - Most optimal way to find the sum of 2 numbers represented as linked lists -


I was trying to write a program for the problem mentioned above, the number (ie lists) can be of uneven length

  • Reverse list-2
  • Search for a yoga and list it in a new list of lists- List <3>
  • Invert list.
  • The complexity of this should be o (n + m). Is it anyway to reduce it, or is it better to do it?

    The best thing I do is store the reverse In order, so 43,712 is stored in this form:

      2 -> 1 - & gt; 7 - & gt; 3 - & gt; 4  

    This arithmetic operation makes very easy.

    Displaying a number can be either more or more simpler with an repeated algorithm Note: It all assumes list of linked lists alone.

    Edit: But you later said that you have no choice in storage format. As such, your best bet is to reverse the two lists, make extra and then reverse the results.


    Comments

    Popular posts from this blog

    asp.net - Javascript/DOM Why is does my form not support submit()? -

    sockets - Delphi: TTcpServer, connection reset when reading -

    javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -