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

}

相关推荐
bkspiderx9 小时前
C++经典的数据结构与算法之经典算法思想:贪心算法(Greedy)
数据结构·c++·算法·贪心算法
中华小当家呐10 小时前
算法之常见八大排序
数据结构·算法·排序算法
tju新生代魔迷11 小时前
数据结构:双向链表
数据结构·链表
songx_9912 小时前
leetcode9(跳跃游戏)
数据结构·算法·游戏
学c语言的枫子12 小时前
数据结构——双向链表
c语言·数据结构·链表
Boop_wu13 小时前
[数据结构] 栈 · Stack
数据结构
kk”13 小时前
C语言快速排序
数据结构·算法·排序算法
3壹14 小时前
数据结构精讲:栈与队列实战指南
c语言·开发语言·数据结构·c++·算法
papership15 小时前
【入门级-算法-6、排序算法:选择排序】
数据结构·算法·排序算法
YS_Geo17 小时前
Redis 深度解析:数据结构、持久化与集群
数据结构·数据库·redis