Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I have a O(len/2) method. I never worked in Delphi, so I'll post the code in C++ (2010 << I hope there's no problem >> ): */
- #include <iostream>
- using namespace std;
- int main(void)
- {
- char S[128], temp;
- cout << "Original string = "; cin.getline(S, sizeof(S));
- for(int i(0), j = strlen(S), k(j >> 1), x; i < k; ++i)
- {
- // Swap
- x = j - i - 1;
- S[i] ^= S[x];
- S[x] ^= S[i];
- S[i] ^= S[x];
- }
- cout << "Reverse string = " << S;
- system("pause>nul");
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment