(p)=t; p is pointer to node and you are changing 'p' for that you need to
use 'call by reference' i.e. use pointer to p or 'node **p' since p is of
type 'node *'
if you are doing (p) = t;  in main function itself then its fine but if you
are calling a function you have to pass node **p

Cheers
Saurabh

On Thu, Dec 18, 2008 at 8:38 PM, aditya <[email protected]> wrote:

>
> plz correct me if am wrong,but dont we just need to change the place
> where p is pointing,and that is possible if we do
>  if(i==0)
>   {
>     t->next =(p);
>      (p)=t;
>     return;
>   }
>
> On Dec 18, 1:29 pm, "Channa Bankapur" <[email protected]>
> wrote:
> > 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