65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
typedef int ElemType;
#define N 4
void permute(ElemType *a, int size);
void rotate(ElemType *a, int size, int m)
int main()
{
int a[N] = {1,2,3,4};
permute(a,N);
}
void permute(ElemType *a , int size)
{
static int n = 0;
if(size ==0)
{
++n;
cout << " #" << n<< " :\t";
for(int i = 0 ; i < N ; ++i)
cout << a[i] << " ";
cout << endl;
}
for(int i = 0 ; i < size ; ++i)
{
permute(a,size-1);
cout <<"%%" << size<<endl; //想把这里的size全装在栈里 然后出栈顺序执行rotate()
rotate(a,N,size);
}
}
void rotate(ElemType *a, int size , int m)
{
ElemType tmp = a[size-m];
for(int i = size-m ; i < size - 1; ++i)
a[i] = a[i+1];
a[ size - 1 ] = tmp;
}