Consider the following pseudocode: declare a queue of characters, which is implemented by circular array of size 6.
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 dequeue the queue
else
enqueue the character into the queue
}How the queue looks like after processing the input "Hello***Wor**ld*"?
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: "(2)", tức mảng vòng có o ở ô 0, r ở ô 1, l ở ô 2, d ở ô 3, còn ô 4 và ô 5 rỗng. Chạy theo chuỗi Hello rồi ba dấu sao, Wor rồi hai dấu sao, ld rồi một dấu sao: H, e, l, l, o chiếm ô 0 đến ô 4; ba dấu sao lấy ra H, e, l nên đầu hàng chuyển về ô 3; W vào ô 5, o quay vòng về ô 0, r vào ô 1; hai dấu sao lấy ra l ở ô 3 và o ở ô 4 nên đầu hàng về ô 5; l vào ô 2, d vào ô 3; dấu sao cuối lấy ra W ở ô 5. Còn lại bốn ký tự o, r, l, d ở các ô 0, 1, 2, 3 với đầu hàng tại ô 0. Bảng "(1)" đặt d ở ô 0 và o, r, l ở ô 3, ô 4, ô 5, tức lệch vòng, trong khi lần quay vòng duy nhất chỉ đưa chữ o của Wor về đúng ô 0. Bảng "(3)" dồn r, l, d xuống ô 0 đến ô 2 và để o ở ô 5, nghĩa là đầu hàng lùi thêm một ô so với thực tế. Bảng "(4)" chiếm ô 1 đến ô 4, ứng với việc nạp H từ ô 1 thay vì ô 0.
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ỏiConsider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop the stack
else
push the character into the stack
}
while(the stack is not empty)
pop and write the poped character to the screen
What is written to the screen for the input "Good**Morn**in***g" ?Có lời giảiCâu hỏiConsider the following pseudocode:
declare a stack of characters
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ó 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