# 字母全排列快速演算法C代碼

`//原理是插入, 在一個字串的所有位置插入新字元.//如: AB 插入C , 位置有 1A2B3, 插入後形成 CAB ACB ABCchar *AllList(char *str, int *pNum)...{    int i, j, k, n;    int len = strlen(str);    int Total = 0;    int count, oldcount;    int size;    char *Buf;    char *p, *p1;    if (len > 10) return NULL;    //計算總的組合數目    for (i = 0, j = 1; i < len; i++)    ...{        j *= (len - i);        Total += j;    }    //建立二維數組, 存放全部組合    size = len + 1;    if ((Buf = (char *)malloc(Total * size)) == NULL)    ...{        return NULL;    }    for (k = 0, count = 0; k < len; k++)  //所有要插入的字元    ...{        oldcount = count;        p = Buf;        p1 = Buf + count * size;        for (i = 0; i < oldcount; i++, p += size)  //插入到所有字串中,形成新的字串        ...{            n = strlen(p);            for (j = 0; j <= n; j++, count++, p1 += size) //在字串所有位置插入            ...{                memcpy(p1, p, n);                p1[n] = p1[j];                p1[j] = str[k];                p1[n + 1] = ''`

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD