一个网友的作业,有点意思,用自定义数据类型方式加入学生信息,然后用冒泡算法排序学生信息,自定义数据类型很简单,就三个数组,但是在编辑框排序这个就很有意思了,用易语言自带的数组排序只能排序一个数组,三个数组的变动索引必须一致才能达到目的,思考了很久,只能自己写个冒泡算法对一个数组进行比对,其他数组跟着修改索引就好了,不知道是不是最简单的方法,贴出来记录一下吧。
窗口程序集名 | 保 留 | 保 留 | 备 注 |
窗口程序集_启动窗口 | |||
变量名 | 类 型 | 数组 | 备 注 |
student | 成绩信息 | 0 |
子程序名 | 返回值类型 | 公开 | 备 注 | ||
__启动窗口_创建完毕 |
子程序名 | 返回值类型 | 公开 | 备 注 | ||
初始化 |
变量名 | 类 型 | 静态 | 数组 | 备 注 | ||
i | 整数型 | |||||
name | 文本型 | 0 | ||||
age | 整数型 | 0 | ||||
score | 小数型 | 0 | ||||
j | 整数型 |
age = { 15, 17, 16, 14, 18, 16, 19, 18, 17, 16 }
score = { 80, 60, 76, 89.5, 90, 90, 50, 80, 99, 78.5 }
重定义数组 (student, 假, 取数组成员数 (name))
编辑框1.加入文本 ( #title )

student [j].name = name [j]
student [j].age = age [j]
student [j].score = score [j]



编辑框1.加入文本 (“| ” + student [i].name + “ | ” + 到文本 (student [i].age) + “ | ” + 到文本 (student [i].score) + “ | ” + #换行符 + “ —————————-” + #换行符 )



子程序名 | 返回值类型 | 公开 | 备 注 | ||
_按钮2_被单击 |
编辑框1.加入文本 ( #title )
冒泡排序 ()
子程序名 | 返回值类型 | 公开 | 备 注 | ||
冒泡排序 |
变量名 | 类 型 | 静态 | 数组 | 备 注 | ||
i | 整数型 | |||||
j | 整数型 | |||||
age | 整数型 | |||||
name | 文本型 | |||||
score | 小数型 |



age = student [j].age
name = student [j].name
score = student [j].score
student [j].age = student [j + 1].age
student [j].name = student [j + 1].name
student [j].score = student [j + 1].score
student [j + 1].age = age
student [j + 1].name = name
student [j + 1].score = score



编辑框1.加入文本 (“| ” + student [i].name + “ | ” + 到文本 (student [i].age) + “ | ” + 到文本 (student [i].score) + “ | ” + #换行符 + “ —————————-” + #换行符 )




按钮2.标题 = “按年龄排序”

数据类型名 | 公开 | 备 注 | ||||
成绩信息 | ||||||
成员名 | 类 型 | 传址 | 数组 | 备 注 | ||
name | 文本型 | |||||
age | 整数型 | |||||
score | 小数型 |
评论前必须登录!
注册