• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Avatar

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

数据结构之排序--选择排序

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

namespace SelectionSort
{

class SelectSort
{
public SelectSort(){}
public int []arr=new int[1000];
public void Sort(int []a)
{
int len=a.Length;
for (int i=0; i<len; i++)
{
int min=i;
for (int j=i; j<len; j++)
{
if (a[min]>a[j])
{
min=j;
}
}
int temp=a[min];
a[min]=a[i];
a[i]=temp;
}
arr=a;
}
public void Display()
{
for(int i=0;i<arr.Length;i++)
{
System.Console.Write(arr[i]+"");
}
}
}
class Program
{

static void Main( string[] args )
{
int[] arr=new int[1000];
Random random=new Random(1000);
for (int i=0; i<1000; i++)
{
int data=random.Next(i);
for (int j=0; j<i; j++)
{
if (arr[j]==data)
{
data=random.Next(i);
j=0;
}
}
arr[i]=data;
}
SelectSort sort=new SelectSort();
sort.Sort(arr);
sort.Display();
System.Console.Read();

}

}
}


编辑器加载中...

posted on 2012-03-27 19:07  lijizhong  阅读(131)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3