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

}

相关推荐
2401_8812444038 分钟前
Treap树
数据结构·算法
乌萨奇也要立志学C++40 分钟前
二叉树OJ题(单值树、相同树、找子树、构建和遍历)
数据结构·算法
hn小菜鸡9 小时前
LeetCode 377.组合总和IV
数据结构·算法·leetcode
亮亮爱刷题10 天前
飞往大厂梦之算法提升-7
数据结构·算法·leetcode·动态规划
_周游10 天前
【数据结构】_二叉树OJ第二弹(返回数组的遍历专题)
数据结构·算法
双叶83610 天前
(C语言)Map数组的实现(数据结构)(链表)(指针)
c语言·数据结构·c++·算法·链表·哈希算法
zmuy10 天前
124. 二叉树中的最大路径和
数据结构·算法·leetcode
转码的小石10 天前
Java面试复习指南:并发编程、JVM、Spring框架、数据结构与算法、Java 8新特性
java·jvm·数据结构·spring·面试·并发编程·java 8
chao_78910 天前
滑动窗口题解——找到字符串中所有字母异位词【LeetCode】
数据结构·算法·leetcode
LZA18510 天前
数据结构day1
数据结构