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);