/// <summary>
/// 排列算法
/// </summary>
/// <param name="list"></param>
/// <param name="start"></param>
/// <param name="end"></param>
public static void quanpailie(int[] list, int start, int end)
{
if (start > end)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("pailie.txt", true))
{
for (int i = 0; i <= end; i++)
{
sw.Write("{0},", list[i]);
}
sw.WriteLine();
sw.Flush();
sw.Close();
}
}
else
{
for (int i = start; i <= end; i++)
{
swap(ref list[start], ref list[i]);//交换位置
quanpailie(list, start + 1, end);
swap(ref list[start], ref list[i]);//交换位置
}
}
}
/// <summary>
/// 交互位置
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap(ref int a, ref int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
private void button2_Click(object sender, EventArgs e)
{
int[] money = { 332191, 307535, 264271, 252131, 221874 };
quanpailie(money, 0, 4);
}