字符串循环移位

来源:互联网 发布:室内烧烤知乎 编辑:程序博客网 时间:2024/05/17 05:01

翻手法

#include<stdio.h>#include<stdlib.h>#include<string.h>/*reverse hand to do rotate right*/void reversehand(char *list, int low , int high){int tmp;while(low<high){tmp = list[low];list[low]=list[high];list[high]=tmp;low++;high--;}}int main(){char *list;int length,n;list = (char *)malloc(sizeof(char));strcpy(list,"abcdefghi");length = strlen(list);printf("how many steps you want to move to right rotate:\n");scanf("%d",&n);reversehand(list,0,length-n-1);reversehand(list,length-n,length-1);reversehand(list,0,length-1);printf("after right shifted %d step(s) the list is :%s\n",n,list);system("pause");return 0;}



0 0
原创粉丝点击