Given a string "abcd", write a function that would make it "dcba"
My idea was to basically swap the first and last element, then swap 2nd and 2nd to last element, etc...
psuedocode:
string Reverse(string input_string)
int front = 0;
int back = input_string.Length -1
string reverse_string = new string(input_string.Length - 1)
while front < back
reverse_string[front] = input_string[back]
reverse_string[back] = input_string[front]
front++
back--
return reverse_string
No comments:
Post a Comment