Thought
- Define two pointers to the tail
- Exchanging the data of the tail pointer
//String rolloverChar*strrev (Char*Str){//Determines whether a character is null or an empty string if(Str= = NULL | |Str==' + ') {return Str; }//define char array pointer Char*start =Str;Char*end =Str; while(*end! =' + '){//point to the last nodeEnd + +; }//Exchange The value of the head and tail CharTemp --end;//Remove the location of the while(Start < end) {temp = *start; *start = *end; *end = temp; Start + +; End--; }return Str;}intMainvoid){Char Str[] ="Wangming"; cout << Strrev (Str);return 0;}
Results
If you can take advantage of the functions of the system, you can define a stack, let the character array into the stack, and then the stack can achieve this effect, but the problem is not to use the resources provided within the system, can only use the original method.
If the time complexity can be lower, please leave a message.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
String rollover-cannot use system functions