标签:算法
//Reverse the whole string,then reverse each word. char* reverseFixlen(char *str,int n) { char *p=str+n-1; char *start=str; while(str<p) { char c=*str; *str=*p; *p=c; ++str; --p; } return start; } void reverseWordInSentence(char* sen) { int len=strlen(sen); char* str=reverseFixlen(sen,len); char* p=str; while(*p!=‘\0‘) { while(*p==‘ ‘&& *p!=‘\0‘) p++; str=p; while (*p!=‘ ‘&&*p!=‘\0‘) p++; reverseFixlen(str,p-str); } }
标签:算法
原文地址:http://blog.csdn.net/wangfengfan1/article/details/45156877