Code:
void insertnode( struct node *new )
{
struct node *cur, *prev;
while( cur != end )
Here you have a problem. Two of them. You shouldn't use the word "new", because while it isn't a keyword in C, it is in C++, and if you ever go to convert this program, you'll get tons of errors. Not really a problem here, but just something to keep in minde.
Second, you use "cur" and "end" without ever giving them values.
Code:
if(head == end)
{
if(head == end)
{
if(strcmp(cur->name,new->name)<0)
You've just tested "head==end", so why do it twice?
Third: this is way to complex.
Given a circular list, do this:
List *myList;
Assuming "myList" is holding some point in a circular list, do this:
Code:
insert( List *toInsert )
{
List *cur, *end;
cur = end = myList;
do {
if ( strcmp( cur->data, toInsert->data ) < 0 )
{
cur = cur->next;
}
else
break;
} while ( cur != end );
/*insert after the end*/
if ( cur == end )
{
toInsert->next = myList;
end->next = toInsert;
}
/*insert after cur*/
else
{
toInsert->next = cur->next;
cur->next = toInsert;
}
}
Your code is WAY to complicated.
Quzah.