| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
学习型 ASP/PHP/ASP.NET 主机 35元/年全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
赛孚耐:软件保护加密专家身份认证令牌USB KEY  
共有 184 人关注过本帖
标题:[求助]C#写希尔排序
收藏  订阅  推荐  打印 
jasonxie
Rank: 3Rank: 3
等级:中级会员
威望:2
帖子:207
积分:2184
注册:2007-3-19
[求助]C#写希尔排序

大家知道数据结构有个排序的内容吧。我用C++写了一个希尔排序,但是我用C#却写不出来了,我感觉逻辑跟C++是一样的啊,为什么输出的时候有问题呢??调了半天也没有调出哪里出问题了,请各位帮帮忙。

using System;
using System.Collections.Generic;
using System.Text;

namespace shellSort
{
class Program
{
public static void swap(ref int a,ref int b)
{
int temp = a;
a = b;
b = a;
}

public static void shellSort(int[] p, int n)
{
int i, j, dis;
dis = n / 2;

while (dis > 0)
{
for (i = dis; i < n; ++i) //循环的次数
{

j = i - dis; //间距

while (j >= 0)
{
if (p[j] > p[j + dis])
swap(ref p[j] ,ref p[j + dis]);
j = j - dis;
}
}
dis = dis / 2;
}
}

static void Main(string[] args)
{
int[] arr = { 82, 16, 9, 95, 27, 75, 42, 69, 34};
shellSort(arr, arr.Length);

for (int i = 0; i < arr.Length; ++i)
Console.Write(" {0} ", arr[i]);

}
}
}

搜索更多相关主题的帖子: 希尔  
2007-6-10 13:09
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.061868 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved