Mindtree Wireless India Interview Question
Software Engineer / Developersfor insert at begnning
insert_beg(struct node **q,int a)
{
struct node *temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=a;
temp->next=*q;
*q=temp;
}
and insert at end is
insert_end(struct node **q,int a)
{
struct node *temp,r;
temp=*q;
while(temp->next!=NULL)
temp=temp>next;
r=malloc(sizeof(struct node));
r->data=a;
r->next=NULL:
temp->next=r;
}
for this we should have the last pointer as well which point to the last node in the list.
- DashDash September 28, 2010