数据结构D1作业

#include<stdio.h>

#include<string.h>

typedef struct stu

{

char name[20];

double height;

int score;

}stu,*stu_p;

int main(int argc, const char *argv[])

{

int i=0;

int j=0;

char temp_name[20]="";

int temp_score=0;

double temp_height=0;

stu arr[7]={};

stu_p p=arr;

for(i=0;i<7;i++)

{

printf("请输入学生姓名>>");

scanf("%s",(p+i)->name);

printf("请输入学生身高>>");

scanf("%lf",&((p+i)->height));

printf("请输入学生成绩>>");

scanf("%d",&((arr+i)->score));

}

for(i=0;i<6;i++)

{

for(j=0;j<6-i;j++)

{

if((*(p+j)).score>(*(p+j+1)).score)

{

temp_score=(*(p+j)).score;

(*(p+j)).score=(*(p+j+1)).score;

(*(p+j+1)).score=temp_score;

temp_height=(*(p+j)).height;

(*(p+j)).height=(*(p+j+1)).height;

(*(p+j+1)).height=temp_height;

strcpy(temp_name,(p+j)->name);

strcpy((p+j)->name,(p+j+1)->name);

strcpy((p+j+1)->name,temp_name);

}

}

}

for(i=0;i<7;i++)

{

printf("%d\t",(*(p+i)).score);

}

printf("\n");

return 0;

}

相关推荐
猎猎长风25 分钟前
【数据结构和算法】3. 排序算法
数据结构·算法·排序算法
乌鸦94442 分钟前
《数据结构之美--双向链表》
数据结构·链表
bookish_2010_prj1 小时前
链式栈和线性栈
数据结构·c++·算法
egoist20231 小时前
【C++指南】哈希驱动的封装:如何让unordered_map/set飞得更快更稳?【上】
数据结构·c++·算法·容器·哈希算法·散列表·c++11
刚入坑的新人编程2 小时前
数据结构——栈和队列
c语言·数据结构·c++·链表·数组
朝新_2 小时前
【数据结构】第四弹——LinkedList与链表
数据结构·链表
祁同伟.3 小时前
OJ - 设计循环队列
c语言·数据结构·算法
啊阿狸不会拉杆4 小时前
数据结构-数组与广义表
java·c语言·数据结构·c++·python·算法
jie188945758665 小时前
数据结构-----目录管理-----1
数据结构
不会计算机的捞地5 小时前
【数据结构入门训练DAY-14】 蓝桥杯2024年第十五届省赛真题-R 格式
数据结构·蓝桥杯