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

}

相关推荐
蚊子码农8 小时前
算法题解记录--239滑动窗口最大值
数据结构·算法
额,不知道写啥。9 小时前
HAO的线段树(中(上))
数据结构·c++·算法
blackicexs10 小时前
第五周第七天
数据结构·算法
夏乌_Wx11 小时前
反转链表:三种实现思路与细节梳理
数据结构·链表
紫陌涵光12 小时前
108.将有序数组转换为二叉搜索树
数据结构·算法·leetcode
载数而行52012 小时前
算法系列2之最短路径
c语言·数据结构·c++·算法·贪心算法
fu的博客13 小时前
【数据结构10】满/完全二叉树、顺序/链式存储
数据结构·
逆境不可逃13 小时前
【除夕篇】LeetCode 热题 100 之 189.轮转数组
java·数据结构·算法·链表
wefg114 小时前
【算法】倍增思想(快速幂)
数据结构·c++·算法
Zik----14 小时前
Leetcode24 —— 两两交换链表中的节点(迭代法)
数据结构·算法·链表