当前位置:首页 » 考试成绩 » 数据结构对学生成绩链表排序

数据结构对学生成绩链表排序

发布时间: 2020-12-13 04:58:57

Ⅰ c语言!!!程序设计:建立一个学生信息链表,包括学号,姓名,成绩.(实现添加,删除,查询,排序,平均)

#include<iostream>

using namespace std;

struct stu{

char name[20];

int num;

int age;

char sex;

int grade;

struct stu *next;

};

struct stu *mythis,*mynew;

void newrecord(struct stu *head)

{

mythis=head->next;

while(mythis!=NULL)

mythis=mythis->next;

mynew=(struct stu *)malloc(sizeof(struct stu));

cin>>mynew->name>>mynew->num>>mynew->age>>mynew->sex>>mynew->grade;

mynew->next=NULL;

if(mythis==NULL)

{

mythis=(struct stu *)malloc(sizeof(struct stu));

mythis=mynew;

}

}

void listall(stu *head)

{

mythis=head->next;

while(mythis!=NULL)

{

cout<<mythis->name<<mythis->num<<mythis->age<<mythis->sex<<mythis->grade;

mythis=mythis->next;

}

}

int main()

{

char decide;

struct stu *head;

head=(struct stu *)malloc(sizeof(struct stu));

head->next=NULL;

while(1)

{

cout<<"Please input decide:"<<endl;

cin>>decide;

if(decide=='n')

newrecord(head);

else

if(decide=='1')

listall(head);

else

return 0;

}

}



拓展资料

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言制定了一套完整的美国国家标准语法,称为ANSI C,作为C语言最初的标准。目前2011年12月8日,国际标准化组织(ISO)和国际电工委员会(IEC)发布的C11标准是C语言的第三个官方标准,也是C语言的最新标准,该标准更好的支持了汉字函数名和汉字标识符,一定程度上实现了汉字编程。



Ⅱ c语言数据结构(双向链表排序)

#include <stdio.h>
#include <stdlib.h>

typedef struct node{
float data;
struct node *pre;
struct node *next;
}*DoubleNode;

void sort_DoubleNode(DoubleNode &head, float data)
{
DoubleNode node = (DoubleNode)malloc(sizeof(struct node));
DoubleNode p,q;
node->data = data;
if(head == NULL)
{
head = node;
head->next = NULL;
head->pre = NULL;
return;
}

p = head;
while(p != NULL && p->data < data)
{
q = p;
p = p->next;
}
if(p == head)
{
node->next = head;
node->pre = NULL;
head ->pre = node;
head = node;
}
else{
q->next = node;
node->pre = q;
node->next = p;
if(p != NULL) p->pre = node;
}
}

void out_DoubleNode(DoubleNode &head)
{
DoubleNode p = head;
while(p != NULL)
{
printf("%.4f ", p->data);
p = p->next;
}
printf("\n");
}

void main()
{
int n;
float data;
DoubleNode head = NULL;
scanf("%d", &n);

for(int i=0; i<n; ++i)
{
scanf("%f", &data);
sort_DoubleNode(head, data);
}

out_DoubleNode(head);
}
/*
15
23.4 4.5 56 67 7.5 90 8.97 90.6 25.6 145
856 10.2 0.36 54.6 56.1
*/

第二题: 测试数据同第一题
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
float data;
struct node *pre;
struct node *next;
}*DoubleNode;

bool bigger(float a, float b)
{
return (a > b);
}

bool smaller(float a, float b)
{
return (a < b);
}

void sort_DoubleNode(DoubleNode &head, float data, bool (*comp)(float a, float b))
{
DoubleNode node = (DoubleNode)malloc(sizeof(struct node));
DoubleNode p,q;
node->data = data;
if(head == NULL)
{
head = node;
head->next = NULL;
head->pre = NULL;
return;
}

p = head;
while(p != NULL && comp(p->data, data))
{
q = p;
p = p->next;
}
if(p == head)
{
node->next = head;
node->pre = NULL;
head ->pre = node;
head = node;
}
else{
q->next = node;
node->pre = q;
node->next = p;
if(p != NULL) p->pre = node;
}
}

void merge_DoubleNode(DoubleNode &head, DoubleNode &head1, DoubleNode &head2)
{
DoubleNode p = head2;
head = head1;
if(head1 == NULL || head2 == NULL) return;
while((head1->next != NULL) && (head2 != NULL))
{
p = head2->next;
head1->next->pre = head2;
head2->next = head1->next;
head2->pre = head1;
head1->next = head2;
head1 = head2->next;
head2 = p;
}
if((head1->next == NULL) && (head2 != NULL))
{
head1->next = head2;
head2->pre = head1;
}
}

void out_DoubleNode(DoubleNode &head)
{
DoubleNode p = head;
while(p != NULL)
{
printf("%.4f ", p->data);
p = p->next;
}
printf("\n");
}

void main()
{
int n;
float data;
DoubleNode head = NULL;
DoubleNode head1 = NULL;
DoubleNode head2 = NULL;
scanf("%d", &n);

for(int i=0; i<n; ++i)
{
scanf("%f", &data);
if((i+1)%2 == 0) sort_DoubleNode(head2, data, &bigger);
else sort_DoubleNode(head1, data, &smaller);
}

merge_DoubleNode(head, head1, head2);

out_DoubleNode(head);
}
/*
15
23.4 4.5 56 67 7.5 90 8.97 90.6 25.6 145
856 10.2 0.36 54.6 56.1
*/

Ⅲ 编写一个程序,要求能完成排序和查找,分别使用链表,数组和二叉树等数据结构,比较各种方法的优缺点。

思路很简单,根来放在源0位置,以后假定当前位置是i,那么左子结点在2i+1,右子结点在2i+2。比如根的左子结点在1,右子结点在2。结点1的左子结点在3,右子结点在4。定义一种空值表示没有子结点,比如empty。
假定一个结点由3个成员组成:value, left, right
数组假定是全局的,如果不是可以作为参数传送。
递归实现比较简单:
void btree2array(node, index)
{
if(node == NULL)
array[index] = empty;
array[index] = node->value;
btree2array(node->left, index * 2 + 1);
btree2array(node->right, index * 2 + 2);
}

开始调用的时候就一句话:
btree2array(root, 0);

Ⅳ 数据结构实验--学生成绩管理,要求建立学生成绩表,用单链表实现

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char name[20];
char num[10];
float score;
}Grade;
typedef struct Lnode
{
Grade mark;
struct Lnode *next;
}Lnode,*Linklist;
Linklist create()
{
int flag=1;
Linklist p,head;
head=NULL;
while(flag!=0)
{
p=(Linklist)malloc(sizeof(Lnode));
printf("请输入学生的姓名、学生的学号以及学生的成绩\n");
scanf("%s%s%f",p->mark.name,p->mark.num,&p->mark.score);
fflush(stdin);
p->next=head;
head=p;
printf("请输入flag的值,为0或者为1,0代表结束输入、1代表继续输入\n");
scanf("%d",&flag);
fflush(stdin);
}
return head;
}
void output(Linklist head)
{
Linklist p;
p=(Linklist)malloc(sizeof(Lnode));
printf("学生姓名、学号、成绩分别为:\n");
for(p=head;p!=NULL;p=p->next)
printf("%s %s %.2f\n",p->mark.name,p->mark.num,p->mark.score);
}
void search(Linklist head,char *num)
{
Linklist p;
p=(Linklist)malloc(sizeof(Lnode));
for(p=head;p!=NULL && strcmp(p->mark.num,num)!=0;p=p->next);
printf("查询的结果为\n");
printf("%s %s %.2f\n",p->mark.name,p->mark.num,p->mark.score);
}
void insert(Linklist head,Grade mark,char *num)//在学号num之前插入一条学生成绩记录
{
Linklist p,q;
p=(Linklist)malloc(sizeof(Lnode));
q=(Linklist)malloc(sizeof(Lnode));
for(p=head;p!=NULL && strcmp(p->next->mark.num,num)!=0;p=p->next);
strcpy(q->mark.name,mark.name);
strcpy(q->mark.num,mark.num);
q->mark.score=mark.score;
q->next=p->next;
p->next=q;
}
void delet(Linklist head,char *num)
{
Linklist p;
p=(Linklist)malloc(sizeof(Lnode));
for(p=head;p!=NULL && strcmp(p->next->mark.num,num)!=0;p=p->next);
p->next=p->next->next;
}
void main()
{
Linklist head;
Grade mark;
head=(Linklist)malloc(sizeof(Lnode));
head=NULL;
head=create();
printf("请输入姓名、学号、成绩");
scanf("%s%s%f",mark.name,mark.num,&mark.score);
output(head);
search(head,"03");
insert(head,mark,"02");
output(head);
delet(head,"03");
output(head);
}

Ⅳ 用C语言实现数据结构中常用算法,如对链表的操作、查找、排序等。

#include <iostream.h>

class ram
{
public:
char wenzi[200];
ram *p;
};

ram wo,*ai=&wo;

int num=0;//我申请了几次内存了

void xie(void);//输入数据,然后分配内存为下次做准备。
void (void);//把写入的数据全部显示出来

int main(void)
{
while(1)//故意死循环
{
xie();
();

}
return NULL;
}

void xie(void)
{
cin.getline(ai->wenzi,200);
cout<<"\n______________________________________________________\n";
if((ai->p=new ram)==NULL) {cout<<"内存申请失败\n";return;}
ai=ai->p;
num++;
}

void (void)
{
ram *ni;
ni=&wo;
int a;
for(a=num;a>0;a--)
{
cout<<ni->wenzi;
cout<<"\n";
ni=ni->p;
}
cout<<"__________________________________________________________\n";

}

Ⅵ 数据结构链表c语言建立学生成绩管理系统

#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include<string.h>

typedefstructdata{
intnumber;
charname[20];
charid[20];
doublescore[3];
}dataType;

typedefstructlist{
dataTypepauline;
structlist*next;
}*LinkList,*pNode,Node;

void*getMemory(size_tsize){
returnmalloc(size);
}

LinkListgetEmptyList(){
LinkListhead=(pNode)getMemory(sizeof(Node));
memset(head,0,sizeof(Node));
returnhead;
}

intaddNode(LinkListhead,pNodepnode){
pNodeq;
for(q=head;q->next;q=q->next)
if(q->next->pauline.number==pnode->pauline.number){
printf("重复的学号:%d ",pnode->pauline.number);
return0;
}
q->next=pnode;
pnode->next=NULL;
return1;
}

//按学号升排序
voidsortNumber(LinkListhead){
pNodep,q,pt,qt;
p=head;
while(p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.number>q->next->pauline.number)
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
p=p->next;
}
}

//按第th门成绩降排序,th=1,2,3
voidsortScore(LinkListhead,intth){
pNodep,q,pt,qt;
inti;
if(th<1||th>3)return;
i=th-1;
for(p=head;p->next;p=p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.score[i]<q->next->pauline.score[i])
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
}
}

voidshow(LinkListhead){
pNodep;
for(p=head->next;p;p=p->next ){
printf("%d %s %s %.2lf %.2lf %.2lf ",
p->pauline.number,p->pauline.name,p->pauline.id,
p->pauline.score[0],p->pauline.score[1],p->pauline.score[2]);
}
}

pNodereadData(){
pNodepnode=(pNode)getMemory(sizeof(Node));
inti;
printf("学号:");
scanf("%d",&pnode->pauline.number);
printf("姓名:");
scanf("%s",pnode->pauline.name);
printf("身份证:");
scanf("%s",pnode->pauline.id);
for(i=0;i<3;++i){
printf("第%d门成绩:",i+1);
scanf("%lf",&pnode->pauline.score[i]);
}
returnpnode;
}

voidmenu(){
printf("******************************** ");
printf("******学生成绩管理系统****** ");
printf("******************************** ");
printf("*1、添加学生信息* ");
printf("*2、显示学生信息* ");
printf("*3、按学号排序* ");
printf("*4、按成绩排序* ");
printf("******************************** ");
printf("*0、退出* ");
printf("******************************** ");
}

intmain(){
charop[20];
intselect;
LinkListhead=getEmptyList();
do{
menu();
printf("请选择:");
fflush(stdin);
fgets(op,20,stdin);
fflush(stdin);
switch(op[0]-'0'){
case1:addNode(head,readData());break;
case2:show(head);break;
case3:sortNumber(head);break;
case4:printf("按第几门功课排序;");
scanf("%d",&select);
sortScore(head,select);
break;
}
}while(op[0]-'0');
printf("END ");
return0;
}

Ⅶ 数据结构,用C语言实现,基于链表的学生成绩管理系统,根据学号和姓名创建索引

看可以不咯?#includeintavgGrade(inta[50]){inti,sum=0,max=0,min=0;doubleavg=0.0;max=a[0];min=a[0];for(i=0;imax)max=a[i];if(a[i]a[i]){temp=a[i];a[i]=a[j];a[j]=temp;}}else{if(a[j]a[i]){for(s=49;s>=i;s--)a[s+1]=a[s];break;}a[i]=n;}intdeleteGrade(inta[50]){intx,i,j;printf("请输入你要删除的成绩:\n");scanf("%d",&x);for(i=0;i<10;i++){if(a[i]==x)for(j=i+1;j<10;j++)a[i]=a[j];a[j]='\0';}}voidmain(){intn,i,a[50];printf("请输入50个学生的成绩:\n");for(i=0;i<50;i++){scanf("%d",&a[i]);}while(1){printf("--------------------------\n");printf("请选择您的功能:\n\n");printf("0录入成绩\n");printf("1输出成绩\n");printf("2输出平均分、最高分、最低分\n");printf("3成绩降序或升序排列\n");printf("4插入一个成绩\n");printf("5删除用户给定的成绩\n");printf("6退出\n\n");printf("--------------------------\n");scanf("%d",n);switch(n){case0:printf("请输入50个学生的成绩:\n");for(i=0;i<50;i++){scanf("%d",&a[i]);}break;case1:for(i=0;i<50;i++){printf("%d",a[i]);}break;case2:avgGrade(a);break;case3:compositor(a);break;case4:insertGrade(a);break;case5:deleteGrade(a);break;case6:exit(0);}}return0;}

Ⅷ 数据结构中:编写10个学生成绩的链表,包括学号、姓名、成绩,并用函数求出最高值最低值和平均值

struct stu
{
int id;
char name[20];
float score;

stu *next;
};

stu *create();
double max(stu *h);
double avg(stu *h);

void main()
{
stu *h=create();
cout<<"最大分数是:"<<max(h)<<endl;
cout<<"平均分:"<<avg(h)<<endl;
}

stu *create()
{
stu *h,*p,*q;
h=(stu*)malloc(sizeof(stu));
h->next=NULL;
p=h;

int i;
for(i=0;i<10;i++)
{
q=(stu*)malloc(sizeof(stu));
q->next=NULL;
cout<<"请输入学号:";
cin>>q->id;
cout<<"请输入姓名:";
cin>>q->name;
cout<<"请输入分数:";
cin>>q->score;

p->next=q;
p=q;
}

return h;
}

double max(stu *h)
{
stu *q;
double max=0;
for(q=h->next;q!=NULL;q=q->next)
{
if(max<q->score)
max=q->score;
}
return max;
}

double avg(stu *h)
{
stu *q;
double sum=0;
for(q=h->next;q!=NULL;q=q->next)
{
sum+=q->score;
}
return sum/10;
}

Ⅸ 数据结构 程序设计 用双向循环链表建立一个学生管理系统,要求实现插入,删除,排序,修改等功能。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
int num;
char name[10];
float score[3];
float total;
struct student *next,*prior;
}DLNode,*DLinkList;

//建立链表
DLinkList Creat_DLinkList()
{
int x;
char y[10];
float s[3];
DLinkList DL=NULL;
DLNode *p=NULL,*q=NULL;
DL=malloc(sizeof(DLNode));
if(DL==NULL)
exit(0);
q=DL;
DL->next=NULL;
DL->prior=NULL;
printf("\nPlease enter students' information:\n");
scanf("%d%s%f%f%f",&x,y,&s[0],&s[1],&s[2]);
while(x!=0)
{
int i;
p=malloc(sizeof(DLNode));
p->num=x;
strcpy(p->name,y);
for(i=0;i<3;i++)
p->score[i]=s[i];
p->total=p->score[0]+p->score[1]+p->score[2];
q->next=p;
p->prior=q;
p->next=DL;
q=p;
scanf("%d%s%f%f%f",&x,y,&s[0],&s[1],&s[2]);
}
DL->prior=q;
return q;
}

//查找
int search(DLinkList r,int n)
{
DLNode *p,*h;
h=r->next;
p=h->next;
while(p!=h)
{
if(p->num==n)
return 1;
p=p->next;
}
return 0;
}

//添加
DLinkList add(DLinkList r)
{
int x;
char y[10];
float s[3];
DLNode *h=r->next,*p=NULL;
p=malloc(sizeof(DLNode));
printf("\nPlease enter students' information:\n");
scanf("%d%s%f%f%f",&x,y,&s[0],&s[1],&s[2]);
while(x!=0)
{
int i;
p=malloc(sizeof(DLNode));
p->num=x;
strcpy(p->name,y);
for(i=0;i<3;i++)
p->score[i]=s[i];
p->total=p->score[0]+p->score[1]+p->score[2];
p->prior=r;
r->next=p;
p->next=h;
h->prior=p;
r=p;
scanf("%d%s%f%f%f",&x,y,&s[0],&s[1],&s[2]);
}
return r;
}

//删除
void delete(DLinkList r)
{
char na[10];
DLNode *h=r->next;
DLNode *p=h->next;
DLNode *q=NULL;
while(p!=h)
{
q=p->next;
while(q!=h)
{
if(!strcmp(q->name,p->name))
{
q->prior->next=q->next;
q->next->prior=q->prior;
free(q);
}
q=q->next;
}
p=p->next;
}
}

//修改
int modify(DLinkList r,int n)
{
float s[3];
int i;
DLNode *h=r->next;
DLNode *p=h->next;
while(p!=h)
{
if(p->num==n)
{
printf("\nPlease enter new score:\n");
scanf("%f%f%f",&s[0],&s[1],&s[2]);
for(i=0;i<3;i++)
p->score[i]=s[i];
p->total=p->score[0]+p->score[1]+p->score[2];
break;
}
p=p->next;
}
if(p==h)
return 0;
else
return 1;
}

//排序
DLinkList sort(DLinkList r)
{
DLNode *t=NULL,*s=NULL;
DLNode *h=r->next;
DLNode *p=h->next;
DLNode *q=NULL;
while(p!=h)
{
q=h->next->next;
while(q!=h)
{
t=q->prior;
if(t->total<q->total)
{
s=t->prior;
t->next=q->next;
q->next->prior=t;
t->prior=q;
q->next=t;
q->prior=s;
s->next=q;
q=t;
}
q=q->next;
}
p=p->next;
}

return h->prior;
}

//输出
void print_DLinkList(DLinkList r)
{
int i;
DLNode *p,*h;
h=r->next;
p=h->next;
while(p!=h)
{
printf("number:%3d\tname:%s\tscore:%5.2f\t%5.2f\t%5.2f\ttotal:%5.2f\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->total);
p=p->next;
}
}

//释放内存
void destory(DLinkList r)
{
DLNode *h,*p,*t=NULL;
h=r->next;
p=h->next;
while(p!=h)
{
t=p->next;
free(p);
p=t;
}
free(h);
}

int main()
{
DLinkList r;
int x,n,k;
r=Creat_DLinkList();
print_DLinkList(r);
printf("\nChoose what you want:\n");
printf("1:Search information:\n");
printf("2:Add information:\n");
printf("3:Delete same name:\n");
printf("4:Modify score:\n");
printf("5:Sort degrdation:\n");
scanf("%d",&x);
switch(x)
{
case 1: printf("\nPlease enter a number:");
scanf("%d",&n);
k=search(r,n);
if(k)
print_DLinkList(r);
else
printf("\nerror!!!\n");
break;
case 2: r=add(r);
print_DLinkList(r);
break;
case 3: delete(r);
print_DLinkList(r);
break;
case 4: printf("\nPlease enter a number:");
scanf("%d",&n);
k=modify(r,n);
if(k)
print_DLinkList(r);
else
printf("\nNot found!!!\n");
break;
case 5: r=sort(r);
print_DLinkList(r);
break;
default:printf("\nEnter error!!!\n");
}

destory(r);
return 0;
}

最近在学这里,所以就帮楼主编了一下,顺便巩固巩固所学。lz有什么不懂的尽管问,我会尽量回答的。

Ⅹ C程序数据结构线性链表 排序sort(面试题 填空题 )自己做了一部分,后面不会做 前面的还不知对否

struct node *create(int a[],int n)
{
struct node *h,*q;
for(h=NULL;n;n--)
{
q=(struct node *)malloc(sizeof(struct node));
q->value=________________________; //应该是n-1,你看main函数里的调用用的是数组大小,而不是用数组下标上限
________________________________; //应该是q->next=h,表头添加节点法,保证表尾为NULL
________________________________; //h=q;
}
return h;
}

while(q-next !=NULL)
{
if(q->next->value<__________________) //应嘎是 r->next->value,因为r是个临时变量,相当于数组排序中的tmp,这里的r是用来保存最小的数的头节点的。这个循环的作用是找剩下的链表中的最小节点r->next。
r=q;
q=q->next; //向后遍历节点
}
if(r !=p) //如果r!=p 就说明 r==p->nex
{
s=_________________________; //s=r->next; 保存最小节点到s
________________________=s->next; //r->next=s->next; 将最小节点从剩下的链表中分离出来
s->next=________________________; //s->next=p->next; 将最小节点连接到p->next
______________________________=s; //p->next=s;
}

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919