enhance swapChar

This commit is contained in:
Sandipsinh Rathod 2024-10-10 20:06:06 -04:00
parent ade69a563e
commit 6f8eb0f0ac

@ -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);
}