forked from Hawstein/cracking-the-coding-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.2.cpp
More file actions
43 lines (39 loc) · 593 Bytes
/
1.2.cpp
File metadata and controls
43 lines (39 loc) · 593 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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;
}