Note that there are some explanatory texts on larger screens.

plurals
  1. POError in trying to count the nodes in circular doubly linked list recursively
    primarykey
    data
    text
    <p>Here is my implementation of count:</p> <pre><code>int count(node *start) { static int l ; node *current; /* Node for travelling the linked list*/ current=start; if(current-&gt;next!=start) { l = 1 + count ( current-&gt;next ) ; return ( l ) ; } else { return(1); } } </code></pre> <p>Here is a fragment of main function where I am calling it:</p> <pre><code>void main() { node *head; printf ( "Length of linked list = %d", count ( head ) ) ; } </code></pre> <p>Here is the structure:</p> <pre><code>struct cirdoublelinklist { struct cirdoublelinklist *prev; /** Stores address of previous node **/ int value; /** stores value **/ struct cirdoublelinklist *next; /** stores address of next node **/ }; /** Redefining list as node **/ typedef struct cirdoublelinklist node; </code></pre> <p>On running and trying to see the length of a list, it crashes with out of bound memory. Please help me with this, I have been working on this for a long time now.</p> <p>Method to add the first node:</p> <pre><code>void initialize(node *start) { start-&gt;prev=start; printf("\nEnter Value\n"); scanf("%d",&amp;start-&gt;value); start-&gt;next=start; } </code></pre> <p>Method to add subsequent nodes after the location specified:</p> <pre><code>void insert_after(node *start) { int num; /* value for inserting a node */ int flag=0; node *newnode; /* New inputed node*/ node *current; /* Node for travelling the linked list*/ newnode=(node*)malloc(sizeof(node)); printf("\nEnter the value after which you want to insert a node\n"); scanf("%d",&amp;num); init(newnode); current=start; while(current-&gt;next!=start) { if(current-&gt;value==num) { newnode-&gt;next=current-&gt;next; current-&gt;next-&gt;prev=newnode; current-&gt;next=newnode; newnode-&gt;prev=current; flag=1; } current=current-&gt;next; } if(flag==0 &amp;&amp; current-&gt;next==start &amp;&amp; current-&gt;value==num) { /*** Insertion checking for last node ***/ newnode-&gt;next=current-&gt;next; /* Start is being copied */ current-&gt;next-&gt;prev=newnode; current-&gt;next=newnode; newnode-&gt;prev=current; flag=1; } if(flag==0 &amp;&amp; current-&gt;next==NULL) printf("\nNo match found\n"); } </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.
 

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