字符串全排列-循环移位法

 
  1. /*用循环移位法解决字符串全排列*/
  2. #include <stdio.h>
  3. #include <string.h>
  4. void shift_one(char str[], int size){
  5.     char tmp = str[0];
  6.     for(int i = 1; i < size; i++){
  7.         str[i - 1] = str[i];
  8.     }
  9.     str[size - 1] = tmp;
  10. }
  11. void all_sort(char str[], int count, int size){
  12.     if(1 == count){
  13.         printf("%s/n", str);
  14.     }
  15.     for(int i = 0; i < count; i++){
  16.         all_sort(str, count - 1, size);
  17.         shift_one(str + (size - count), count);
  18.     }
  19. }
  20. int main_string_all_sort(){
  21.     char str[] = {"abcd"};
  22.     all_sort(str, 4, 4);
  23.     return 0;
  24. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值