Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   create link list (http://www.go4expert.com/forums/create-link-list-t9589/)

answerme 24Mar2008 20:04

create link list
 
Hi
This prg is for creating a link list .But Iam not able to understand what will last line do q->link=tmp;

Code:

int create(int data)
{
        struct node *q,*tmp;
       
        tmp=malloc(sizeof(struct node));
        tmp->info=data;
        tmp->link=NULL;
       
        if(start==NULL)
                start=tmp;
        else
        {       
                q=start;
                while(q->link!=NULL)
                {
                        q=q->link;
                }
               
                        q->link=tmp; // why this is required
        }
}


shabbir 25Mar2008 11:31

Re: create link list
 
It will assign the last node ( the one which is being created ) at the end of the q

lead.smart34 25Mar2008 15:19

Re: create link list
 
in temp you are taking the data to be inserted in the linked list .

so you are attaching that node as the next node of q here


All times are GMT +5.5. The time now is 15:28.