Hi; Friends;
I solved most of the work. But it's now having problem to insert in the middle.
Any can suggest me where to correct, how to correct, and where I did mistake.
Here is my that insertnode function:
....Code ..........
struct node *head = (struct node *) NULL;
struct node *end = struct node *) NULL;
......
void insertnode(struct node *insert)
{
struct node *curr, *prev;
if(head == NULL)
{
head = insert;
insert->next=head;
end=insert;
}
else if(head==end)
{
if(strcmp(head->name,insert->name) < 0)
{
insert->next=head;
head->next=insert;
end=insert;
}
else {
head=insert;
insert->next=end;
end->next=head;
}
}
/* inserting in the middle part is here....*/
/*...........Problem here ............*/
/* .........segmentation error....... */
else{
curr = head;
while(strcmp(curr->name,insert->name) < 0) {
curr = curr->next;
if(curr==head)
break;
}
if(curr=head){
insert->next=head;
head=insert;
}
else{
prev=head;
while(prev->next!=curr){
prev=prev->next;
}
prev->next=insert;
insert->next=curr;
if(end==prev)
end=insert;
}
}
}