字符串全排列-循环移位法
2008-10-27 21:54
148 查看
/*用循环移位法解决字符串全排列*/
#include <stdio.h>
#include <string.h>
void shift_one(char str[], int size){
char tmp = str[0];
for(int i = 1; i < size; i++){
str[i - 1] = str[i];
}
str[size - 1] = tmp;
}
void all_sort(char str[], int count, int size){
if(1 == count){
printf("%s/n", str);
}
for(int i = 0; i < count; i++){
all_sort(str, count - 1, size);
shift_one(str + (size - count), count);
}
}
int main_string_all_sort(){
char str[] = {"abcd"};
all_sort(str, 4, 4);
return 0;
}
#include <stdio.h>
#include <string.h>
void shift_one(char str[], int size){
char tmp = str[0];
for(int i = 1; i < size; i++){
str[i - 1] = str[i];
}
str[size - 1] = tmp;
}
void all_sort(char str[], int count, int size){
if(1 == count){
printf("%s/n", str);
}
for(int i = 0; i < count; i++){
all_sort(str, count - 1, size);
shift_one(str + (size - count), count);
}
}
int main_string_all_sort(){
char str[] = {"abcd"};
all_sort(str, 4, 4);
return 0;
}
相关文章推荐
- 【算法15】字符串的全排列
- 算法题/用递归实现一个字符串的全排列
- 字符串 全排列生成问题
- 字符串的全排列
- 编程之法:面试和算法心得(字符串的全排列)
- 算法-字符串全排列问题
- 字符串的全排列
- 字符串的全排列
- 剑指offer系列之二十六:输出字符串的全排列
- 字符串的全排列_全组合
- 字符串的全排列
- 求字符串全排列的递归算法
- 《剑指offer》:[28]字符串的全排列问题
- 左旋转字符串(数组循环移位)
- [LeetCode] 567. Permutation in String 字符串中的全排列
- 字符串的全排列详解
- 【100题】第五十三题 字符串的全排列
- (Relax ST1.7)POJ 1256 Anagram(求一个字符串在特殊规定下的全排列)
- C#学习笔记:生成字符串的全排列
- 黑马程序员_求任意字符串及其所有子串的全排列