For any string $\text{str, length(str)}$ returns the length of the string, $\text{append(str1, str2)}$ concatenates $\text{str1}$ with another string $\text{str2}$, and $\text{trim(str)}$ removes any spaces that exist at the end of the string $\text{str}$. The function $\text{reverse(str, i, j)}$ reverses the part of the string from position $i$ to position $j$. Assume that position $0$ refers to the first character in the string. What does the following pseudo-code do?
def manipulate(string str)
{
reverse(str, 0, length(str)-1);
append(str,' ');
n=length(str);
j=0;
for(i=0; i<n; i=i+1)
{
if(str[i] is ' ')
{
reverse(str, j, i-1);
j = i + 1;
}
}
trim(str);
return str;
}