线性表链表
来源:互联网 发布:js添加json元素 编辑:程序博客网 时间:2024/03/28 21:49
//输入n个学生信息(姓名,成绩),再按成绩降序输出这些信息
#include<stdio.h>
#include<stdlib.h>
//------------------------
struct student
{
char name[10];
float score;
struct student *next;
};
//------------------------
struct student *insert(struct student *head)
{
struct student *p,*pnew,*pold;
pnew=(struct student *)malloc(sizeof(struct student));
scanf("%s%f",pnew->name,&pnew->score);//建立新节点
p=head;
if(pnew->score>head->score)
{
pnew->next=p;
head=pnew;
}
else
{
while(p!=NULL&&pnew->score<p->score)
{
pold=p;
p=p->next;
}
pnew->next=p;
pold->next=pnew;
}
return head;
}
//------------------------
void print(struct student *head)
{
struct student *p=head;
while(p!=NULL)
{
printf("%s%.1f/n",p->name,p->score);
p=p->next;
}
}
//------------------------
void main()
{
struct student *head;
int i,n;
scanf("%d",&n);
head=(struct student *)malloc(sizeof(struct student));
scanf("%s%f",head->name,&head->score);
head->next=NULL;
for(i=1;i<n;i++)
{
head=insert(head);
}
print(head);
}
#include<stdio.h>
#include<stdlib.h>
//------------------------
struct student
{
char name[10];
float score;
struct student *next;
};
//------------------------
struct student *insert(struct student *head)
{
struct student *p,*pnew,*pold;
pnew=(struct student *)malloc(sizeof(struct student));
scanf("%s%f",pnew->name,&pnew->score);//建立新节点
p=head;
if(pnew->score>head->score)
{
pnew->next=p;
head=pnew;
}
else
{
while(p!=NULL&&pnew->score<p->score)
{
pold=p;
p=p->next;
}
pnew->next=p;
pold->next=pnew;
}
return head;
}
//------------------------
void print(struct student *head)
{
struct student *p=head;
while(p!=NULL)
{
printf("%s%.1f/n",p->name,p->score);
p=p->next;
}
}
//------------------------
void main()
{
struct student *head;
int i,n;
scanf("%d",&n);
head=(struct student *)malloc(sizeof(struct student));
scanf("%s%f",head->name,&head->score);
head->next=NULL;
for(i=1;i<n;i++)
{
head=insert(head);
}
print(head);
}
- 线性表链表
- 线性表链表
- 线性表链表实现
- 线性表链接实现--双循环链表
- 数据结构第二章--线性表链表
- 数据结构学习---线性表链表实现
- 线性表链式实现
- 线性表链式实现
- 线性表链式存储
- 线性表链式存储
- 线性表链式 实现
- 线性表链式存储
- 线性表链式存储
- 线性表链式存储
- 线性表链式存储
- 线性表链式存储
- 线性表链接存储
- 线性表链式存储结构实现--静态链表
- 深刻剖析经典面试题之三:关于虚函数
- 微软ASP.NET2.0开源代码
- XML详解----Schema
- 游戏可用性研究
- JavaScript 控制表格宽度
- 线性表链表
- 堆栈实现十进制转换二进制
- Gridview导出到Excel,Gridview中的各类控件,Gridview中删除记录的处理
- 不熟悉数据类型的定义
- 今天与遇到的eclipse WTP插件问题
- 实现GridView控件的删除多条记录功能系列(1)
- 每天都是感恩节
- 正则表达式相关学习
- 感悟人生三大境界