两种字符串逆序方式

来源:互联网 发布:linux下apache配置php 编辑:程序博客网 时间:2024/06/16 00:29
#include <iostream>#include <cstring>using namespace std;void swap(char &a, char &b){    a = a^b;    b = a^b;    a = a^b;}void reverse2(char *s){    int n = strlen(s);    for(int i=0; i<n/2; ++i)        swap(s[i], s[n-i-1]);}void reverse(char *s){    char *end = s;    char tmp;    if(s)    {        while(*end)            ++end;        --end;        while(s < end)        {            tmp = *s;            *s++ = *end;            *end-- = tmp;        }    }}int main(){    char s[] = "1234567890";    reverse2(s);    cout<<s<<endl;    return 0;    }