zoukankan      html  css  js  c++  java
  • 输出数组的全排列

    今天参照网上写的输出数组的全组合

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    /*writed by telnetning on 5/13,2013
    *perm writed to output all Combination of a array
    */
        
    #include <stdio.h>
        
    /*swap used to switch two numbers value*/
    void swap(int *pi, int*pj)
    {
        int temp;
        temp = *pi;
        *pi = *pj;
        *pj = temp;
    }
        
    /*create all combination*/
    void perm(int i,int n,int list[])
    {
        int j;
        if(i == n){
            printf("list:");
            for(j = 0; j <= n ;j++){
                printf("%d ", list[j]);
            }
            printf("\n");
        else {
            for( j = i; j <= n; j++){
                swap(&list[i],&list[j]);
                perm(i+1,n,list);
                swap(&list[j],&list[i]);
            }
        }
    }
        
    int main()
    {
        int list[8] = {1,2,3,4,5,6,7,8};
        
        perm(0,7,list);
        
        return 0;
    }

     

  • 相关阅读:
    c++命名规范与代码风格
    subline的多行游标快捷键
    selenium中的action
    Fiddler 教程(转)
    java.util.NoSuchElementException解决办法
    http协议中的URI
    深入研究java.lang.Runtime类(转)
    深入研究java.lang.Process类(转)
    java调用autoit3脚本
    AutoIT转
  • 原文地址:https://www.cnblogs.com/telnetning/p/3084833.html
Copyright © 2011-2022 走看看