严重缺钱,找了份短期派遣工作.
因为开口说的语言能力还算新手,并且是做原来完全没接触过的C#, 所以老板给找了几个语言好的,经验和我差不多的同事带我.
但似乎工作速度有点过快, 上周五中午就完成了所有工作,甚至基本不加班.
结果,这周四他们还没完成.
上周日,老板专门找我谈话,要我照顾一下大家的情绪,不要把所有精力放在工作上,有空多学学别的.
在尝试学语言,研究源程序代码等等过程,而且不能让大家发现的情况下,
终于,找到了一个似乎在办正事,
我又感兴趣的事情:用C#书写算法代码.
以下是我根据算法的实现方式写得冒泡排序代码,欢迎指正.
BTW,没有中文输入法,只能用Google翻译写拼音来写文章真累.
using System;
namespace ConsoleApp1
{
class BubbleSort
{
static void Main(string[] args)
{
int[] list = { 5, 3, 7, 11, 6, 10, 2, 4, 1 };
//int[] list = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//int[] list = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
bubbleSortMethod( list );
//selectionSortMethod( list );
Console.ReadKey();
}
static void bubbleSortMethod(int[] sortList )
{
int temp = 0;
int exchangeCnt = 0;
int endLenth = sortList.Length;
do
{
Console.WriteLine( "endLenth:{0}", endLenth );
Console.WriteLine( "------------------------------------------------" );
for ( int i = 0; i < sortList.Length; i++ )
{
Console.WriteLine( sortList[ i ].ToString() );
}
Console.WriteLine( "------------------------------------------------" );
exchangeCnt = 0;
for ( int i = 0; i < endLenth - 1; i++ )
{
if ( sortList[ i ] > sortList[ i + 1 ] )
{
temp = sortList[ i + 1 ];
sortList[ i + 1 ] = sortList[ i ];
sortList[ i ] = temp;
exchangeCnt += 1;
}
}
endLenth -= 1;
} while ( exchangeCnt > 0 & endLenth > 1 );
Console.WriteLine( "------------------------------------------------" );
Console.WriteLine( "The final sortList is :" );
for ( int i = 0; i < sortList.Length; i++ )
{
Console.WriteLine( sortList[ i ].ToString() );
}
return;
}
}
}