edited by
289 views
1 votes
1 votes

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

 

edited by

1 Answer

Related questions

1 votes
1 votes
2 answers
1
soujanyareddy13 asked Jan 29, 2021
590 views
Consider the following program. Assume that $x$ and $y$ are integers.f(x, y) { if (y != 0) return (x * f(x,y-1)); else return 1; }What is $f(6,3)?$$243$$729$$125$$216$
1 votes
1 votes
2 answers
2
soujanyareddy13 asked Jan 29, 2021
549 views
Consider the matrix $A=\begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}$. Find $A^n,$ in terms of $n,$ for $n\geq2.$
2 votes
2 votes
1 answer
4
soujanyareddy13 asked Jan 29, 2021
320 views
In the figure shown below, the circle has diameter $5$. Moreover, $AB$ is parallel to $DE.$ If $DE=3$ and $AB=6,$ what is the area of triangle $ABC?$