enhance swapChar
This commit is contained in:
parent
ade69a563e
commit
6f8eb0f0ac
10
main.cpp
10
main.cpp
@ -100,9 +100,12 @@ bool isValidPlayer(char c) {
|
||||
}
|
||||
|
||||
void swapChar(char &a, char &b) {
|
||||
char temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
if (a == b) {
|
||||
return;
|
||||
}
|
||||
a ^= b;
|
||||
b ^= a;
|
||||
a ^= b;
|
||||
}
|
||||
|
||||
// Recursively reverse a string
|
||||
@ -112,6 +115,7 @@ void reverseString(string &str, int start, int end) {
|
||||
}
|
||||
|
||||
swapChar(str[start], str[end]);
|
||||
|
||||
reverseString(str, start + 1, end - 1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user