Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well for starters there something wrong here:<br></p> <pre><code> if (list1Ptr == NULL &amp;&amp; list2Ptr != NULL) { list1Ptr = list2Ptr; head = list1.head; break; } </code></pre> <p>If you are done traversing list1 then what you want is to point the last node of list1 to point at list2. <code>list1Ptr = list2Ptr;</code><br> is doing nothing of that. It is merely changing the local variable's value.<br> Same for this part:</p> <pre><code> else if (list2Ptr == NULL &amp;&amp; list1Ptr != NULL) { list2Ptr = list1Ptr; head = list1.head; break; } </code></pre> <p>This is a bad of doing things:<br> <code>list1Ptr->data > list2Ptr->data &amp;&amp; list1Ptr != NULL &amp;&amp; list2Ptr != NULL</code><br> If list1Ptr becomes NULL then if you try to access NULL->data there is surely going to be trouble(since generally the expression will be executed left to right).<br> Also:</p> <pre><code> else if (list1Ptr-&gt;data &gt; list2Ptr-&gt;data &amp;&amp; list1Ptr != NULL &amp;&amp; list2Ptr != NULL) { typename List&lt;T&gt;::Node* temp = list2Ptr; list2Ptr = list2Ptr-&gt;next; temp-&gt;next = list1Ptr; } </code></pre> <p>There is something really wrong here too. You first store list2ptr in a temp. Then you move list2ptr to the next node in list2. But why make <code>temp->next = list1ptr</code>?<br> You should be re thinking that part out. And same for the next else block.<br> Best.<br> EDIT:<br> Alright, let's see what more can be done:<br> Here is the psuedo code I suggest you use:</p> <pre><code>func(list1,list2): ptr1 = list1.head ptr2 = list2.head declare pointer curr if(ptr1!= NULL and ptr2!=NULL){ if(ptr1-&gt;data &lt; prt2-&gt;data) {curr = ptr1 ptr1 = ptr1-&gt;next head = curr } else{ curr = ptr2 ptr1 = ptr2-&gt;next head = curr}} else{ head = whichever one is not NULL, or NULL if both of them are and return } while(ptr1 != NULL and ptr2!=NULL){ if(ptr1-&gt;data &lt; ptr2-&gt;data){ curr-&gt;next = ptr1 curr = ptr1 ptr1 = ptr1-&gt;next continue} else{ curr-&gt;next = ptr2 curr = ptr2 ptr2 = ptr2-&gt;next continue} } if(ptr1 == NULL) curr-&gt;next = ptr2 else curr-&gt;next = ptr1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload