设顺序表VA中的数据元素递增有序.试写一算法,将X插入到顺序表的适当位置上,以保持该表的有序性.
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/09 03:28:30
设顺序表VA中的数据元素递增有序.试写一算法,将X插入到顺序表的适当位置上,以保持该表的有序性.
设顺序表VA中的数据元素递增有序.试写一算法,将X插入到顺序表的适当位置上,以保持该表的有序性.
设顺序表VA中的数据元素递增有序.试写一算法,将X插入到顺序表的适当位置上,以保持该表的有序性.
struct st
{
int data;
struct st *next;
};
struct st *insenode(struct st *head,int x)
{
struct st *new,*last,*current;
new =(struct st *)malloc(sizeof(struct st));
new->data=x;
current=head;
while(x>current->data && current->data!=null)
{
last=current;
current=current->next;
}
if(xdata)
{
if(current==head)
{
new->next=head;
head=new;
}
else
{
new->next=current;
last->next=new;
}
}
else
{
new->next=null;
current->next=new;
}
return(new);
}
不懂的地方再问我