问一道C语言数据结构的编程题,求助高手帮忙~!

已知单链表中La中数据元素按非递减有序排列。按两种不同情况,分别写出算法将元素x插入到La合适位置上,保持该表有序性:1、La带头节点 2、la不带头节点....

基础点的代码就可以,先谢谢了!

这个程序是以前做的,看起来复杂,其实是太多的判断和提示内容而已,你看看主函数,再运行一下,再看看创建链表的函数,关键部分并不多,应该不难看懂,另外模块我做的比较细,有些函数你不必理会,希望能帮到你,谢谢
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SN 2 //科目数量(score number)
typedef struct student
{
char num[10],
name[10];
float score[SN],
sum,
avg;
struct student *next;
}STU;
/**********输入链表单元内容************/
void input(STU *p)
{
int i;
printf("please input number:\n");
scanf("%s",p->num);
printf("please input name:\n");
scanf("%s",p->name);
printf("please input %d scores:\n",SN);
p->sum=0;
for(i=0;i<SN;i++)
{
scanf("%f",&p->score[i]);
p->sum+=p->score[i];
}
p->avg=p->sum/SN;
}
/**********创建一个链表单元**********/
STU *creat_node()
{
STU *p;
p=(STU *)malloc(sizeof(STU));
if(p == NULL)
{ printf("No enough memory !");
exit(0);
}
input(p);
p->next=NULL;
return p;
}

/**********创建一个链表**********/
STU *creat_list()
{
STU *head=NULL,*p;
char str[4];
printf("List creating...\n");
do
{
printf("Do you want to continue (yes/no) :");
scanf("%s",str);
if(strcmp(str,"yes")==0)
{
p=creat_node();
if(head==NULL)
p->next=head;//前插法
head=p;
}
if(strcmp(str,"yes")!=0&&strcmp(str,"no")!=0)
{
printf("You must input 'yes' or 'no'.\n");
//getchar();
continue;
}

if(strcmp(str,"no")==0)break;
//getchar();
}while(1);
printf("List create end...\n\n");
return head;
}
/************输出一个链表头部**********/
void print_a_head()
{
int i;
printf("number\tname\tavg\tsum\t");
for(i=0;i<SN;i++)
printf("score%d\t",i+1);
putchar(10);
}
/************输出一个链表单元**********/
void print_a_node(STU *fin)
{
int i;
printf("%s;\t%s;\t%0.2f;\t%0.2f\t",fin->num,fin->name,fin->avg,fin->sum);
for(i=0;i<SN;i++)
printf("%0.2f\t",fin->score[i]);
putchar(10);
}

/************输出链表**********/
int print_list(STU *stu)
{
STU *p=stu;
if(stu==NULL)
{
printf("no records!!!\n");
return (0);
}
print_a_head();
while(p!=NULL)
{
print_a_node(p);
p=p->next;
}
putchar(10);
return (0);
}

void main()
{
STU *head;
head=creat_list();//创建链表
print_list(head);//输出链表
}
另外,站长团上有产品团购,便宜有保证
温馨提示:答案为网友推荐,仅供参考
相似回答