#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
using namespace std;
#define elemType int
//交换arr数组中位置a和b处的两个元素
void arrySwap(elemType arr[], elemType a, elemType b)
{
elemType temp;
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
int cnt = 0;
//全排列
void perm(elemType arr[], int start, int end)
{
if(start == end)
{
cnt++;
cout<<"第"<<cnt<<"种排列:";
for(int i = 0; i <= end; i++)
cout<<arr[i]<<" ";
cout<<endl;
}
else
{
for(int i = start; i <= end; i++)
{
arrySwap(arr, start, i);
perm(arr, start + 1, end);
arrySwap(arr, start, i);
}
}
}
void main()
{
int arr[5] = {1, 2, 3, 4, 5};
perm(arr, 0, 4);
system("pause");
}
今天做了个测试,发现手生的厉害 %>_<%
要找不到工作的节奏么。
好运,来!
GOGO