⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fullarray.c

📁 全排列实现算法
💻 C
字号:
#include <stdio.h>

#define N 4
#define MAX 24

int full[MAX][N];
int m=0;
int pl[MAX]={0};

void FullArrage(int a[],int n)
{
    int i;
    static int output[N];
    if(n==0)
    {
        int index=0;
        while(index<N)
        {
            full[m][index]=output[index];
            index++;
        }
        m++;
    }
    else
    {
        for(i=0;i<n;i++)
        {
            output[n-1]=a[i];
            a[i]=a[0];
            a[0]=output[n-1];

            FullArrage(a+1,n-1);

            output[n-1]=a[i];
            a[i]=a[0];
            a[0]=output[n-1];
        }
    }
}

void joint(int a[MAX][N],int b[MAX])
{
    int i,j;
    for(i=0;i<MAX;i++)
    {
        for(j=0;j<N;j++)
        {
            b[i]=b[i]*10+a[i][j];
        }
    }
}

void sort(int a[],int n)
{
    int i,j;
    int temp;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
            if(a[i]>=a[j])
            { temp=a[i]; a[i]=a[j];a[j]=temp; }
    }
}

void print(int a[],int m)
{
    int i;
    for(i=0;i<m;i++)
        printf("%d\n",a[i]);

}

main()
{
    int a[N]={1,2,3,4};
    FullArrage(a,N);
    joint(full,pl);
    sort(pl,MAX);
	printf("The %d's FullArray are:\n",N);
    print(pl,MAX);
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -