From 3d2ab7022f2ecd4d00cd12f2612608b58fb1218d Mon Sep 17 00:00:00 2001 From: xuzigui <3542624849@qq.com> Date: Tue, 25 Apr 2023 19:42:53 +0800 Subject: [PATCH] =?UTF-8?q?XZG=5FSortbyName=E6=B5=81=E7=A8=8B=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++ SortbyName.svg | 189 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 SortbyName.svg diff --git a/README.md b/README.md index 2e07897..7ac7165 100644 --- a/README.md +++ b/README.md @@ -456,6 +456,12 @@ step 4:总分,平均分,学号,姓名依次交换 ![按选择法将数组 num 的元素从低到高排序](AsScortNum.svg) #### SortbyName +step 1:利用for循环将相邻的两个姓名作比较 +step 2:如果前一个字符串大于后一个,利用for循环交换m门课程的成绩 +step 3:依次交换 + +![交换法实现字符串按字典顺序排序](SortbyName.svg) + #### SearchbyNum Step 1:利用for循环给 i 赋值为 0 diff --git a/SortbyName.svg b/SortbyName.svg new file mode 100644 index 0000000..03f5f5f --- /dev/null +++ b/SortbyName.svg @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + SortbyName + + + + + + End + + + + + + + + + + + + + + + Integer i + + + + + + + + Integer j + + + + + + + + Integer t + + + + + + + + + + + + + + + + + + + + + + + strcmp(stu[j].name, stu[i]. + name) < 0 + + + + + + + + + + + + + + + + + + + + + + SwapFloat(&stu[i].score[t], & + stu[j].score[t]) + + + + + + t = 0 to m-1 + + + + Next + + + Done + + + + + + + + SwapFloat(&stu[i].sum, &stu[j]. + sum) + + + + + + + + SwapFloat(&stu[i].aver, &stu[j]. + aver) + + + + + + + + SwapLong(&stu[i].num, &stu[j]. + num) + + + + + + + + SwapChar(stu[i].name, stu + [j].name) + + + + + + + + True + + + False + + + + + + j = i+1 to n-1 + + + + Next + + + Done + + + + + + i = 0 to n-2 + + + + Next + + + Done + + + + +