Note that there are some explanatory texts on larger screens.

plurals
  1. POCode hangswhile running
    primarykey
    data
    text
    <p>The code hangs while executing. Please help me to understand what is the problem here It stcks after the first travers and does not even enters the reverse function. Could not understand the issue: Help me on it.</p> <pre><code># include&lt;iostream&gt; # include&lt;stdlib.h&gt; using namespace std; struct sLL { int data; sLL * next; }; void createList(sLL ** head, int n) { if(n == 0) { return; } sLL * temp = (sLL *) malloc(sizeof(sLL)); if(temp != NULL) { temp-&gt;data = rand() % 100; temp-&gt;next = NULL; *head = temp; //head = &amp;(temp-&gt;next); createList(&amp;(temp-&gt;next), n - 1); } } void traverse(sLL * head) { cout&lt;&lt;"In traverse"&lt;&lt;endl; while(head) { cout&lt;&lt;head-&gt;data&lt;&lt;"-&gt;"; head=head-&gt;next; } cout&lt;&lt;"NULL"&lt;&lt;endl; cout.flush(); return; } sLL* reverse(sLL * head) { sLL * temp = NULL, * newNode = NULL; while(head) { newNode = head-&gt;next; // to traverse forword head-&gt;next = temp; temp = head; // Current node value which we use in next itr as a previous node value. newNode = head; // assigning newNode vlaue back to head so that we can traverse forward. } return temp; // final node value will be in temp i.e the current node value. } int main() { int n; sLL * head = NULL, *temp = NULL; cout&lt;&lt;"Enter the number of nodes :"; cin&gt;&gt;n; createList(&amp;head, n); cout&lt;&lt;"\nCreate Done"&lt;&lt;endl; traverse(head); cout.flush(); cout&lt;&lt;"Reverse Start"; temp = reverse(head); cout&lt;&lt;"reverse done"; traverse(temp); } </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.
 

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