数据结构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;

}

相关推荐
酿情师7 小时前
区块链原理与技术02:区块链的数据结构04(区块结构)
数据结构·区块链
夏日听雨眠7 小时前
数据结构(循环队列)
数据结构·算法·链表
平行侠7 小时前
30MacLaren-Marsaglia算法故事文件
数据结构·算法
平行侠8 小时前
33水库抽样 - 从未知大小的流中等概率采样
数据结构·算法
Controller-Inversion9 小时前
42. 接雨水
数据结构·算法·leetcode
Controller-Inversion9 小时前
33. 搜索旋转排序数组
数据结构·算法·leetcode
宵时待雨9 小时前
优选算法专题6:模拟
数据结构·c++·算法·leetcode·职场和发展
Liangwei Lin9 小时前
LeetCode 35. 搜索插入位置
数据结构·算法·leetcode
L_090710 小时前
【C++】STL— 封装红黑树以实现map 和 set
数据结构·c++
此生决int10 小时前
快速复习之数据结构篇——二叉树(三)
数据结构