It's necessary to handle the scenario of i=0. So, if the node has to
be inserted in the beginning of the list, the pointer p to the list
has to change. With your suggested solution, it wouldn't be possible
to see the changed value of p in the calling function. If you assume
you would never insert the node in the beginning of the list, then you
can use your suggested solution.

-Channa

On Thu, Dec 18, 2008 at 2:13 AM, aditya <[email protected]> wrote:
>
> i saw this code to insert a node in a linklist,but i dont get whats
> the need to use **p.Cant I just use *p
>
> void insertlist(intnode**p,int i,intnode *t)   //use *p
> {
>   int j;
>   intnode *q,*x;
>   if(i==0)
>   {
>     t->next =(*p);        //t->next=p;
>     (*p)=t;                 //p=t;
>     return;
>   }
>   q=*p;                   //q=p;
>   for(j=1;(j<i) && (q!=NULL);j++)
>   q=q->next;
>   if(q==NULL && i>0)
>   return;
>   x=q;
>   t->next=x->next;
>   x->next=t;
>   return;
> }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to