| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1517 人关注过本帖
标题:C++三位状态比较排序 再发一个排序法
取消只看楼主 加入收藏
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
结帖率:0
收藏
 问题点数:0 回复次数:7 
C++三位状态比较排序 再发一个排序法
程序运行截图
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 比较 排序 状态 运行 C++ 
2020-01-29 19:12
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
修改错误后的排序截图
图片附件: 游客没有浏览图片的权限,请 登录注册

修改的错误为添加如下判断
if (A > C)
    J = A, A = C, C = J, k = true;

测试用例
程序代码:

    int aa[] = { 99, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66,
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66,
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6 },
        xu = 0, ci = 0, j = 0, jian = 0, lian = sizeof(aa) / sizeof(aa[0]); bool k = false;

2020-01-29 19:14
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
修改错误后的排序截图
图片附件: 游客没有浏览图片的权限,请 登录注册

修改的错误为添加如下判断
if (A > C)
    J = A, A = C, C = J, k = true;

测试用例
程序代码:

    int aa[] = { 99, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66,
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66,
        6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33,
        3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55,
        5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77,
        7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6,
        9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8,
        77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1,
        99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6 },
        xu = 0, ci = 0, j = 0, jian = 0, lian = sizeof(aa) / sizeof(aa[0]); bool k = false;

2020-01-29 19:14
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
改进型排序。
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2022-2-10 21:40编辑过]

2022-02-06 14:46
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
普通数组遍历,尚未写成递归。 家用电脑测试,开网络视频播放器等。对这样的排序效果很满意了,一次整理头尾4个数据,并使得中间数据逐渐逼近正确位置,最好情况O(N),最坏情况也不会出现O(N*N),最坏情况有待专家测试得出结论。
2022-02-06 14:47
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
平均每趟整理到位7个数据。还有哪个排序法能达到并超过我这样效果?
2022-02-08 12:43
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
升级版观音兰花手平均每趟整理到位12个数据,有较大提高,无论置前或置后,另加一条不会有太大提高。
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2022-2-9 05:03编辑过]

2022-02-08 19:06
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2022-2-10 21:32编辑过]

2022-02-10 21:27
快速回复:C++三位状态比较排序 再发一个排序法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.139093 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved