[C#] 纯文本查看 复制代码
class AlgorithmClass
{
/// <summary>
/// 冒泡算法
/// </summary>
/// <param name="IntArray">int数组</param>
/// <returns></returns>
public static int[] BubbleInt(int [] IntArray)
{
for (int i = 0; i < IntArray.Length-1; i++)
{
for (int j = i+1; j < IntArray.Length; j++)
{
if (IntArray > IntArray[j])
{
IntArray = ArraySwitching(IntArray, j, i);
}
}
}
return IntArray;
}
/// <summary>
/// 直接排序算法
/// </summary>
/// <param name="IntArray">int数组</param>
/// <returns></returns>
public static int[] DirectInt(int[] IntArray)
{
for (int i = 0; i < IntArray.Length-1; i++)
{
int IntTemp = i;
for (int j = i+1; j < IntArray.Length; j++)
{
if (IntArray[IntTemp] > IntArray[j])
{
IntTemp = j;
}
}
if (IntTemp!=i)
{
IntArray= ArraySwitching(IntArray,IntTemp,i);
}
}
return IntArray;
}
/// <summary>
/// 数组位置交换
/// 将数组中索引i的值跟索引num的值进行交换
/// </summary>
/// <param name="Array">交换数组</param>
/// <param name="i">数组索引i</param>
/// <param name="num">数组索引num</param>
/// <returns>返回交换后数组</returns>
public static int[] ArraySwitching(int[] Array,int i,int num )
{
int Temp = Array[i];
Array[/i][/i][/i][i][i][i][i] = Array[num];
Array[num] = Temp;
return Array;
}
}