虽然说很多算法都不怎么经常用到,但是还是不可缺少的,而且这些东西很容易被遗忘掉,
所以本人就在这里给自己做个总结,以方便以后使用,很多也想不起来了,还有待添加。
都是一些比较容易用到的算法。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public static void Fibonacci()
{
int sum = 0;
int a = 1;
int b = 1;
while (a < 100)
{
int temp = a;
sum += a;
Console.Write(temp + " ");
a = b;
b = temp + b;
}
Console.Write(sum);
}
/// <summary>
/// 斐波那契数列 递归算法
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static int Foo(int i)
{
if (i == 0)
return 0;
if (i ==1)
return 1;
return Foo(i - 1) + Foo(i - 2);
}
/// <summary>
/// 冒泡排序法
/// </summary>
/// <returns></returns>
static public int[] BubbleSort()
{
int temp = 0;
int[] array = new int[] { 6, 7, 1, 9, 4, 2, 43, 74, 12, 3, 46, 5 };
for (int i = 0; i <= array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i] < array[j])
{
temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
return array;
}
//待添加...............................................