将数字倒序输出
/*============================================================================
Name : Exercise.cpp
Author : Haier
Version : 1.01
Copyright : Copyright (c) 2014
Description : Permute program in C, Ansi-style, Compile by Code:Block
============================================================================*/
#include <iostream>
using namespace std;
void RotateLeft(int *MyArray,int i,int j)
{
int k,Temp=MyArray[i];
for(k=i; k<j-1; k++)
{
MyArray[k]=MyArray[k+1];
}
MyArray[j-1]=Temp;
}
void Swap(int *MyArray,int i,int j)
{
int Temp;
Temp=MyArray[i];
MyArray[i]=MyArray[j];
MyArray[j]=Temp;
}
void Show(int *MyArray,int Size)
{
int i;
for(i=0; i<Size; i++)
{
cout<<MyArray[i];
}
cout<<endl;
}
void Permute(int *MyArray,int First,int Finally)
{
int i,j;
Show(MyArray,Finally);
for(i=Finally-2; i>=First ;i--)
{
for(j=i+1; j<Finally; j++)
{
Swap(MyArray,i,j);
Permute(MyArray,i+1,Finally);
}
RotateLeft(MyArray,i,Finally);
}
}
int main()
{
int i,Test[20],Count;
cout<<"Please input Count:";
cin>>Count;
for(i=0; i<Count; i++)
{
Test[i]=i+1;
}
Permute(Test,0,Count);
return 0;
}