冒泡排序 int[] array = new int[5] { 1, 4, 2, 5, 3 };利用冒泡排序发输出 输出应为1,2,3,4,5 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 复习了一遍 private void button1_Click( object sender, EventArgs e ) { int[] array = new int[ 5 ] { 1, 4, 2, 5, 3 }; for( int i = 0 ; i < array.Length - 1 ; i++ ) { for( int j = 0 ; j < array.Length - 1 ; j++ ) { if( array[ j ] < array[ j + 1 ] ) { int temp = array[ j ]; array[ j ] = array[ j + 1 ]; array[ j + 1 ] = temp; } } } string re = string.Join( ",", Array.ConvertAll<int, string>( array, new Converter<int, string>( x => x.ToString() ) ) ); MessageBox.Show( re ); } public void Sort(int[] arr) { int i, j, temp; bool done = false; j = 1; while ((j < arr.Length) && (!done))//判断长度 { done = true; for (i = 0; i < arr.Length - j; i++) { if (arr[i] > arr[i + 1]) { done = false; temp = arr[i]; arr[i] = arr[i + 1];//交换数据 arr[i + 1] = temp; } } j++; } } int[] array = new int[5] { 1, 4, 2, 5, 3 }; for(int i=1;i< arr.Length;i++){ for(int j=(arr.Length-1);j>=i;j--) { if(arr[j+1]<arr[j]) { int temp= arr[j]; arr[j+1]=arr[j]; arr[j] = temp; } }} 楼上就不错啊 ,两个For()循环,一个If()比较一下就OK了 http://blog.csdn.net/gisfarmer/archive/2009/02/04/3860272.aspxhttp://blog.csdn.net/gisfarmer/archive/2009/01/21/3839014.aspx 熟Linq To Entity 的进来帮下忙,遇到麻烦了! 怎么用C#实现用键盘上的上下左右键来控制游戏中的人物 C#中如何直接删除文件的一行? web 程序问题,请大家帮忙! 求手机号、移动手机号、联通手机号的正则表达式! 应用程序与数据库的中间接口! 如何解决客户端webservice传递参数长度限制? 幼稚问题 给分[20] 向高手请教: 关于查询结果显示的问题!! 用myForm.Show()时,myForm怎么是空的,连标题都没有了! ASP gridview绑定后控件失效了 保存数组问题
private void button1_Click( object sender, EventArgs e ) {
int[] array = new int[ 5 ] { 1, 4, 2, 5, 3 }; for( int i = 0 ; i < array.Length - 1 ; i++ ) {
for( int j = 0 ; j < array.Length - 1 ; j++ ) {
if( array[ j ] < array[ j + 1 ] ) {
int temp = array[ j ];
array[ j ] = array[ j + 1 ];
array[ j + 1 ] = temp;
}
}
} string re = string.Join( ",", Array.ConvertAll<int, string>( array, new Converter<int, string>( x => x.ToString() ) ) );
MessageBox.Show( re );
}
{
int i, j, temp;
bool done = false;
j = 1;
while ((j < arr.Length) && (!done))//判断长度
{
done = true;
for (i = 0; i < arr.Length - j; i++)
{
if (arr[i] > arr[i + 1])
{
done = false;
temp = arr[i];
arr[i] = arr[i + 1];//交换数据
arr[i + 1] = temp;
}
}
j++;
}
}
int[] array = new int[5] { 1, 4, 2, 5, 3 }; for(int i=1;i< arr.Length;i++)
{
for(int j=(arr.Length-1);j>=i;j--)
{
if(arr[j+1]<arr[j])
{
int temp= arr[j];
arr[j+1]=arr[j];
arr[j] = temp;
}
}
}