Consider the following pseudocode: declare a stack of characters
4 phương ánCó giải thích
while(there are more characters in the word to read){read a character if a character is '*' then pop and write the poped character to the screen
else
push the character into the stack
}What is written to the screen for the input "Good**Morn**i***ng" ?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "donrioM". Ngăn xếp nhả theo nguyên tắc vào sau ra trước, nên mỗi dấu sao lấy đúng ký tự vừa được đẩy vào gần nhất. Chạy tay trên Good hai sao Morn hai sao i ba sao ng: đẩy G, o, o, d rồi hai dấu sao nhả d và o, ngăn xếp còn G, o; đẩy M, o, r, n rồi hai dấu sao nhả n và r, ngăn xếp còn G, o, M, o; đẩy i rồi ba dấu sao nhả i, o và M; hai ký tự n, g cuối chỉ được đẩy vào mà không còn dấu sao nào. Ghép theo thứ tự nhả được d, o, n, r, i, o, M. Vì vậy "donrioo" sai vì ở lần nhả thứ bảy đỉnh ngăn xếp là M chứ không phải o; "donrioG" sai vì G nằm dưới cùng, phải nhả M rồi o rồi mới tới nó; "donriMG" sai vì ngay sau khi nhả i thì đỉnh là o của Good, nó bỏ qua ký tự đang nằm trên M.
Cùng phần 2
Select the statement that is most correct.
Which of the following applications may not use a stack?Có lời giảiCâu hỏiSuppose we are implementing a stack of Integers using a singly linked list where the head of the list is treated as the top of the stack.
Specify the correct implementation of push() method of the stack. (Choose the most suitable one)Có lời giảiCâu hỏiConsider the following pseudocode:
declare a queue of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
dequeue the queue
else
enqueue the character into the queue
}
while(the queue is not empty)
dequeue and write the dequeued character to the screen
What is written to the screen for the input "HowAre***You**To**Day " ?Có lời giảiCâu hỏiCả 51 câu của chủ đề51 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây