数据结构已知带头结点的动态单链表L中的结点时按整数数值递增排列的,试写一算法将值为X的结点插入表L中,使L仍然有序。
void insert(struct LNode **p,ElemType x)
{
strct LNode *s=*p,*t,*u;
while (s!=NULL && s->datanext;
}
u=(struct LNode *)malloc(sizeof(struct LNode));
if (s==NULL)
{
t->next=u;
u->next=NULL;}
else
{
if (s==*p)
{
u->next=s;
*p=u;
}
else
{
u->next=s;
t->next=u;
}
}
。 全部
void insert(struct LNode **p,ElemType x)
{
strct LNode *s=*p,*t,*u;
while (s!=NULL && s->datanext;
}
u=(struct LNode *)malloc(sizeof(struct LNode));
if (s==NULL)
{
t->next=u;
u->next=NULL;}
else
{
if (s==*p)
{
u->next=s;
*p=u;
}
else
{
u->next=s;
t->next=u;
}
}
。
收起