Answer to Question #241230 in Algorithms for Selma

Question #241230
1. Study the following algorithm fragment, and answer the questions that follows.
declare a stack of characters
while (there are more characters in the word to read)
{
read a character;
push the character on the stack;
}
while (the stack is not empty)
{
pop a character off the stack;
write the character to the screen;
}
 If the input to the above algorithm is; {This is good time for DSA}
a. What is the value of top if the stack is full?
a. What will be the output of the algorithm for the given input
1
Expert's answer
2021-09-24T13:26:23-0400
1.
while (there are more characters in the word to read)
{
read a character;
push the character on the stack;
}

If stack is full, then the value on the top of stack is last word which we push in the last of the loop.

Or we can say the last character of the stack will be on the top if the stack is full.

2.
while (the stack is not empty)
{
pop a character off the stack;
write the character to the screen;
}

If we are doing pop-up the values, then the output will of the program will be the opposite as just of insertion series.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS