首页 > 编程语言 > 详细

数组希尔排序法

时间:2018-06-24 10:09:18      阅读:194      评论:0      收藏:0      [点我收藏+]

https://blog.csdn.net/lucky51222/article/details/26110199

 

1. 构造算法类

class XiEr  
{  
    public void ssort(int[] a, int n, int sp)  
    {  
        int i, j, t;  
        for (i = 0; i < n - sp; i++)  
            for (j = i; j < n - sp; j += sp)  
                if (a[j] > a[j + sp])  
                {  
                    t = a[j]; a[j] = a[j + sp]; a[j + sp] = t;  
                }  
    }  
  
    public void shellsort(int[] a, int n, int[] d, int dn)  
    {  
        int i;  
        for (i = 0; i < dn; i++)  
            ssort(a, n, d[i]);  
    }  
}  

2. 前端调用

            int j;  
            int[] a = { 49, 38, 100, 97, 76, 13, 27, 49, 55, 4 };  
            int[] d = { 5, 3, 1 };  
            XiEr xier = new XiEr();  
            xier.shellsort(a, 10, d, 3);  
            listBox1.Items.Clear();  
            string tt = "";  
            for (j = 0; j < 10; j++)  
                tt = tt + a[j].ToString() + \t;  
            listBox1.Items.Add(tt);  

数组希尔排序法

原文:https://www.cnblogs.com/CelonY/p/9219253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!