_在路上

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//显示字符串的全排列组合
void DisAllStrExt (char * str, int low, int high)
{
    int     index;

    if (low >= high - 1)
    {
        for (index = 0; index < high; index++)
            putchar(str[index]);
        puts("\r\n");
    }
    else
    {
        for (index = low; index < high; index++)
        {
            char c      = str[low];
            str[low]    = str[index];
            str[index]  = c;
            DisAllStrExt(str, low + 1, high);
            c           = str[low];
            str[low]    = str[index];
            str[index]  = c;
        }
    }    
}

int main ()
{
    char str[] = "abcd";

    DisAllStrExt(str, 0, strlen(str));

    return 0;
}
posted on 2012-10-07 22:00  _在路上  阅读(219)  评论(0编辑  收藏  举报