100分求教 怎么样对数组快速排序.

xunuo230 2009-05-13 01:34:56
String[] gyoshaKbList = row["GYOSHA_KB"].ToString().Split(',');
row["GYOSHA_KB"]里面的数据为 1到14 数字.一个或多个, 不重复,

怎么样把gyoshaKbList 进行下快速排序.(除了像冒泡这种循环 ,因为已经在好多循环里了..想让程序快一点.)

Sort() 这个方法.好像只能给数字排序..gyoshaKbList里面用Split(',');填充进去..好像是当成字符了.

在线等.
...全文
137 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
ASPNETDB 2009-05-13
  • 打赏
  • 举报
回复
不错
tkscascor 2009-05-13
  • 打赏
  • 举报
回复
强淫~~~
xunuo230 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ojlovecd 的回复:]
引用 7 楼 xunuo230 的回复:
引用 2 楼 ojlovecd 的回复:
C# code

Array.Sort(gyoshaKbList , delegate(string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });


果然高人.非常好用..这段代码能讲一下吗?

Array.Sort方法的这个重载,第二个参数是一个泛型委托,传入自己定义的排序方法即可,
这里我传入的是一个匿名方法,由于你说这里面都是数字,所以,调用它本身的CompareTo方法即可…
[/Quote]

非常感谢...现在去结贴
我姓区不姓区 2009-05-13
  • 打赏
  • 举报
回复
6楼的方法是调用Array.Sort的另一个重载
其第二个参数是一个实现了IComparer接口的类,自己在类里实现排序逻辑,效果跟我那个是一样的,不过当然是直接用匿名方法来得简洁
我姓区不姓区 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xunuo230 的回复:]
引用 2 楼 ojlovecd 的回复:
C# code

Array.Sort(gyoshaKbList , delegate(string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });


果然高人.非常好用..这段代码能讲一下吗?
[/Quote]
Array.Sort方法的这个重载,第二个参数是一个泛型委托,传入自己定义的排序方法即可,
这里我传入的是一个匿名方法,由于你说这里面都是数字,所以,调用它本身的CompareTo方法即可实现
HDNGO 2009-05-13
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] Marks = {70, 75, 84, 53, 46, 90, 25 };
int I = Marks.Length;

Console.Write("初始排序为:70, 75, 84, 53, 46, 90, 25");
System.Threading.Thread.Sleep(2000);

Array.Sort(Marks);
Console.WriteLine("");
Console.WriteLine("按照从小到大的顺序排序后为:");
System.Threading.Thread.Sleep(2000);

for (int x = 0; x < I; x++)
{
Console.WriteLine(Marks[x]);
System.Threading.Thread.Sleep(1000);
}
Console.Read();
}
}
}
HDNGO 2009-05-13
  • 打赏
  • 举报
回复
Array.Reverse(Interger);

Array.Sort(Integer);
xunuo230 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ojlovecd 的回复:]
C# code

Array.Sort(gyoshaKbList , delegate(string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
[/Quote]

果然高人.非常好用..这段代码能讲一下吗?
ralpha08 2009-05-13
  • 打赏
  • 举报
回复
class MainClass
{
static void Main()
{

String[] gyoshaKbList = row["GYOSHA_KB"].ToString().Split(',');
Array.Sort(gyoshaKbList, new SortClass());
}
}

class SortClass : IComparer
{
public int Compare(string x, string y)
{
return int.Parse(x) > int.Parse(y)?-1:1;
}

}
gyouyang 2009-05-13
  • 打赏
  • 举报
回复
板凳
SK_Aqi 2009-05-13
  • 打赏
  • 举报
回复
zzxap 2009-05-13
  • 打赏
  • 举报
回复
gyoshaKbList.sort()
我姓区不姓区 2009-05-13
  • 打赏
  • 举报
回复


Array.Sort(gyoshaKbList , delegate(string s1, string s2) { return int.Parse(s1).CompareTo(int.Parse(s2)); });
xunuo230 2009-05-13
  • 打赏
  • 举报
回复
等啊等...

110,530

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧