请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 7291|回复: 14

C#排序算法(发个帖子,庆祝一下C#版块的开通)

[复制链接]

新浪微博达人勋

发表于 2011-8-24 23:32:18 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
     冒泡排序
   
    
  using System;

   
  namespace BubbleSorter
  {
  public class BubbleSorter
  {
  public void Sort(int [] list)
  {
  int i,j,temp;
  bool done=false;
  j=1;
  while((j<list.Length)&&(!done))
  {
  done=true;
  for(i=0;i<list.Length-j;i++)
  {
  if(list[i]>list[i+1])
  {
  done=false;
  temp=list[i];
  list[i]=list[i+1];
  list[i+1]=temp;
  }
  }
  j++;
  }
   
   
  }
  }
  public class MainClass
  {
  public static void Main()
  {
  int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
  BubbleSorter sh=new BubbleSorter();
  sh.Sort(iArrary);
  for(int m=0;m<iArrary.Length;m++)
  Console.Write("{0} ",iArrary[m]);
  Console.WriteLine();
  }
  }
  }
   
   
    选择排序
    
   
  using System;
   
   
  namespace SelectionSorter
  {
  public class SelectionSorter
  {
  private int min;
  public void Sort(int [] list)
  {
  for(int i=0;i<list.Length-1;i++)
  {
  min=i;
  for(int j=i+1;j<list.Length;j++)
  {
  if(list[j]<list[min])
  min=j;
  }
  int t=list[min];
  list[min]=list[i];
  list[i]=t;
  }
   
   
  }
  }
  public class MainClass
  {
  public static void Main()
  {
  int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47};
  SelectionSorter ss=new SelectionSorter();
  ss.Sort(iArrary);
  for(int m=0;m<iArrary.Length;m++)
  Console.Write("{0} ",iArrary[m]);
  Console.WriteLine();
   
   
  }
  }
  }
   
   
    插入排序
   
   
   
  using System;
   
   
  namespace InsertionSorter
  {
  public class InsertionSorter
  {
  public void Sort(int [] list)
  {
  for(int i=1;i<list.Length;i++)
  {
  int t=list[i];
  int j=i;
  while((j>0)&&(list[j-1]>t))
  {
  list[j]=list[j-1];
  --j;
  }
  list[j]=t;
  }
   
   
  }
  }
  public class MainClass
  {
  public static void Main()
  {
  int[] iArrary=new int[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47};
  InsertionSorter ii=new InsertionSorter();
  ii.Sort(iArrary);
  for(int m=0;m<iArrary.Length;m++)
  Console.Write("{0}",iArrary[m]);
  Console.WriteLine();
  }
  }
  }
   
   
    希尔排序
   
   
   
  using System;
   
   
  namespace ShellSorter
  {
  public class ShellSorter
  {
  public void Sort(int [] list)
  {
  int inc;
  for(inc=1;inc<=list.Length/9;inc=3*inc+1);
  for(;inc>0;inc/=3)
  {
  for(int i=inc+1;i<=list.Length;i+=inc)
  {
  int t=list[i-1];
  int j=i;
  while((j>inc)&&(list[j-inc-1]>t))
  {
  list[j-1]=list[j-inc-1];
  j-=inc;
  }
  list[j-1]=t;
  }
  }
  }
  }
  public class MainClass
  {
  public static void Main()
  {
  int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
  ShellSorter sh=new ShellSorter();
  sh.Sort(iArrary);
  for(int m=0;m<iArrary.Length;m++)
  Console.Write("{0} ",iArrary[m]);
  Console.WriteLine();
  }
  }
  }

评分

参与人数 1威望 +1 金钱 +10 贡献 +1 收起 理由
传说中的谁 + 1 + 10 + 1 很实用的东东,感谢鼠标

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2011-8-24 23:33:41 | 显示全部楼层
坐个沙发先~
希望这个版块越来越好
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-24 23:36:19 | 显示全部楼层
支持一个,呵呵
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-24 23:41:29 | 显示全部楼层
没想到啊,鼠标还会C#@Mouse
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2011-8-24 23:43:32 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-24 23:43:52 | 显示全部楼层
科普了,希望都也能尽快入门了。。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-25 01:05:05 | 显示全部楼层
虽然不懂,不过慢慢学习
密码修改失败请联系微信:mofangbao

新浪微博达人勋

0
早起挑战累计收入
发表于 2011-8-25 08:19:04 | 显示全部楼层
哈哈 原来鼠标也用这个啊  我也用的这个  @MeteoInfo也是用的c# 希望这个版块能火起来喽
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-25 09:10:40 | 显示全部楼层
来支持一下鼠标版
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2011-8-25 12:00:02 | 显示全部楼层
支持一下鼠标,火起来迟早的事
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表