#include <iostream>
#include <hash_map>
using namespace std;
using namespace __gnu_cxx;
void reverse1 (string& str){
int end = str.length()-1;
char tmp;
for(int i=0;i<= str.length()/2;i++){ //s
if (i!=end){
tmp=str[i];
str[i]=str[end];
str[end] = tmp;
end --;
}
if(end ==i){
return;
}
}
return ;
}
//----solution2--------------
void reverse2 (char* str ){
char* end =str;
std::cout <<"hello,kitty "<<end<<std::endl;
char tmp;
if (str) {
while (*end){
++end;
}
}
std::cout <<"**\t"<<end-1<<"**"<<std::endl;
std::cout <<"**\t"<<*(end-1)<<"**"<<std::endl;
--end;
while(str <end){
tmp =*str;
*str++ =*end;
*end--=tmp;
}
}
#include <iostream>
#include <hash_map>
using namespace std;
using namespace __gnu_cxx;
void reverse1 (string& str){
int end = str.length()-1;
char tmp;
for(int i=0;i<= str.length()/2;i++){
if (i!=end){
tmp=str[i];
str[i]=str[end];
str[end] = tmp;
end --;
}
if(end ==i){
return;
}
}
return ;
}
//----solution2--------------
void reverse2 (char* str ){
char* end =str;
std::cout <<"hello,kitty "<<end<<std::endl;
char tmp;
if (str) {
while (*end){
++end;
}
}
std::cout <<"**\t"<<end-1<<"**"<<std::endl;
std::cout <<"**\t"<<*(end-1)<<"**"<<std::endl;
--end;
while(str <end){
tmp =*str;
*str++ =*end;
*end--=tmp;
}
}
int main(){
string str = "abcdefg";
str ="abcd";
reverse2((char*)str.c_str());
std::cout<< str<<std::endl;
str ="abcde";
reverse2((char*)str.c_str());
std::cout<< str<<std::endl;
str ="a";
reverse2((char*)str.c_str());
std::cout<< str<<std::endl;
str =" ";
reverse2((char*)str.c_str());
std::cout<< str<<std::endl;
}