找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 26|回复: 0

选择排序算法

[复制链接]

351

主题

341

回帖

2433

积分

管理员

积分
2433
发表于 2025-6-17 21:58:12 | 显示全部楼层 |阅读模式
// Selection Sort
(*
首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置;
再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾;
重复第二步,直到所有元素均排序完毕。
*)
#sort_temp := #Sort_IN;

FOR #i := 1 TO #LEN - 1 DO
    #min := #i;
    FOR #j := #i + 1 TO #LEN DO
        IF (#Asc_Des AND #sort_temp[#j] < #sort_temp[#min]) OR (NOT #Asc_Des AND #sort_temp[#j] > #sort_temp[#min]) THEN
            // #sort_temp[#j] < #sort_temp[#min],升序
            #temp := #sort_temp[#min];
            #sort_temp[#min] := #sort_temp[#j];
            #sort_temp[#j] := #temp;
        END_IF;
    END_FOR;
END_FOR;

#Sort_OUT := #sort_temp;


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|笔记

GMT+8, 2025-7-7 08:05 , Processed in 0.042088 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表