|
struct node
{
char * name;
struct node * next;
};
struct node * Head;
Head-> name = NULL;
Head-> next = NULL;
void insert (struct node * newnode)
{
struct node * p, * q;
p = Head;
q = p;
if (p-> next == NULL)
{
p-> next = newnode;
newnode-> next = NULL;
}
else
{
while (p-> next! = NULL || strcmp (p-> name, newnode-> name) <0)
{
q = p;
p = p-> next;
}
q-> next = newnod;
newnod-> next = q;
}
return;
}
void del (struct node * oldnode)
{
struct node * p, * q;
p = Head;
if (p-> next == NULL)
{
printf ("there is no data\n");
exit (1);
}
else
{
while (p-> next! = NULL || strcmp (p-> name, oldnode-> name)! = 0)
{
q = p;
p = p-> next;
}
q-> next = p-> next;
delete (p);
}
return;
}
The brother who just wrote helps find errors
Is there a good algorithm for sequential search? |
|