C#中生成随机数排序问题

shikun520 2010-05-23 12:48:46
现在是主界面有一个文本框输入要生成多少随机数!有两个按键!一个是确定生成随机数,一个是对生成的数据数进么排序!
我现在的问题是怎么才能让对其排序!麻烦各位大家了!麻烦加注释!
生成随机数代码如下:
int MAXVAL=100;
private void btnGenerate_Click(object sender, EventArgs e)
{
bool flag;
int i;

flag = int.TryParse(txtNumber.Text, out number);
if (!flag)
{
MessageBox.Show("Enter whole didits only", "Input Error");
txtNumber.Focus();
return;
}

Random rnd=new Random(number);



data = new int[number];
lstOutPut.Items.Clear();
lstSorted.Items.Clear();

for (i = 0; i < data.Length; i++)
{
data[i] = rnd.Next(MAXVAL);//MAXVAL=100;
lstOutPut.Items.Add(data[i].ToString());
}


private void btnSort_Click(object sender, EventArgs e)
{
//排序方法
}
...全文
278 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-05-23
  • 打赏
  • 举报
回复
List<int> lst=new List<int>();
lst.Sort
Random ra = new Random(DateTime.Now.Millisecond);

arr.Soert
gsq_0912 2010-05-23
  • 打赏
  • 举报
回复
┏┛┻━━━┛┻┓
┃||||||||||||||┃  
┃   ━   ┃
┃ ┳┛ ┗┳ ┃
┃       ┃
┃   ┻   ┃
┃       ┃
┗━┓   ┏━┛
  ┃ 围 ┃           
  ┃ 观 ┃  
  ┃ 木 ┃  
  ┃ 有 ┃  
  ┃ 罪 ┃
  ┃ ! ┃           
  ┃   ┃  
  ┃   ┃  
  ┃ 保 ┃  
  ┃ 持 ┃
  ┃ 队 ┃           
  ┃ 型 ┃  
  ┃   ┃  
  ┃   ┃  
  ┃   ┃  
  ┃   ┃
  ┃   ┗━━━┓
  ┃       ┣┓
  ┃继续     ┃
  ┗┓┓┏━┳┓┏┛
   ┃┫┫ ┃┫┫
   ┗┻┛ ┗┻┛
mngzilin 2010-05-23
  • 打赏
  • 举报
回复
http://blog.csdn.net/mngzilin/archive/2010/04/24/5525002.aspx

这里面排序和绑定listbox都有了
xiongxyt2 2010-05-23
  • 打赏
  • 举报
回复
随机生成得数放在一个数组里面,用数组的Sort方法排序,遍历数组输出
输出可以用如下方法
string[] A = new string[5] { "a1","a2","a3","a4","a5"};

//第一种方法

for (int i = 0; i < A.Length; i++)
{
Console.WriteLine(A[i]);
}

//第二种方法
IEnumerator e= A.GetEnumerator();
while (e.MoveNext())
{
Console.WriteLine(e.Current.ToString());
}

//第三种方法
foreach (string s in A)
{
Console.WriteLine(s);
}
shikun520 2010-05-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 mngzilin 的回复:]
引用 2 楼 shikun520 的回复:
引用 1 楼 wuyq11 的回复:
List<int> lst=new List<int>();
lst.Sort
Random ra = new Random(DateTime.Now.Millisecond);

arr.Soert

请问!怎么输出来?



怎么输出来?
messagebox,textbox都是可输出……
[/Quote]

我的输出框是一个listbox 麻烦你,写出来看看!~谢谢了!
mngzilin 2010-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 shikun520 的回复:]
引用 1 楼 wuyq11 的回复:
List<int> lst=new List<int>();
lst.Sort
Random ra = new Random(DateTime.Now.Millisecond);

arr.Soert

请问!怎么输出来?
[/Quote]


怎么输出来?
messagebox,textbox都是可输出的地方。
shikun520 2010-05-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
List<int> lst=new List<int>();
lst.Sort
Random ra = new Random(DateTime.Now.Millisecond);

arr.Soert
[/Quote]
请问!怎么输出来?

110,571

社区成员

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

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

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