69,382
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
using namespace std;
int start = 2;
void Perm(int list[],int k,int m)
{
void Swap(int *p1,int *p2);
int i;
if(k == m)
{
for(i=start;i <=m;i++) //问题,每次从第0个元素开始输出
printf("%5d",list[i]);
printf("\n");
}
else
{
for(i=k;i <=m;i++)
{
Swap(&list[k],&list[i]);
Perm(list,k+1,m);
Swap(&list[k],&list[i]);
}
}
}
void Swap(int * p1,int * p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
void main()
{
int a[5]={1,2,3,4,5};
Perm(a,start,3);
//getch();
system("pause");
}
#include <stdio.h>
#include <conio.h>
void Perm(int list[],int start, int k,int m)
{
void Swap(int *p1,int *p2);
int i;
if(k==m)
{
for(i=start;i <=m;i++) //问题,每次从第0个元素开始输出
printf("%5d",list[i]);
printf("\n");
}
else
for(i=k;i <=m;i++)
{
Swap(&list[k],&list[i]);
Perm(list,start, k+1,m);
Swap(&list[k],&list[i]);
}
}
void Swap(int * p1,int * p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
int main()
{
int a[5]={1,2,3,4,5};
Perm(a,1,1,3);
getch();
}