create link list

answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
It will assign the last node ( the one which is being created ) at the end of the q
lead.smart34's Avatar, Join Date: Feb 2008
Contributor
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