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****Worl**d*"?
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: "(4)", tức mảng vòng có r ở ô 1, l ở ô 2, d ở ô 3, còn các ô 0, 4, 5 trống. Mảng sáu ô, nạp từ ô 0 trở đi, mỗi dấu sao lấy ra ở đầu hàng. Chuỗi vào lần lượt là H, e, l, l, o, bốn dấu sao, W, o, r, l, hai dấu sao, d, một dấu sao. Chạy theo đó: H, e, l, l, o chiếm các ô 0 đến 4; bốn dấu sao lấy ra H, e, l, l nên đầu hàng lùi tới ô 4 chỉ còn o; W vào ô 5, rồi o, r, l quay vòng vào các ô 0, 1, 2; hai dấu sao kế tiếp lấy ra o ở ô 4 và W ở ô 5; d vào ô 3; dấu sao cuối lấy ra o ở ô 0. Còn lại r ở ô 1, l ở ô 2, d ở ô 3. Phương án "(1)" đặt r ở ô 4, l ở ô 5 và d ở ô 0, lệch đúng một vòng so với vị trí thật. Phương án "(2)" đặt r ở ô 5, l ở ô 0 và d ở ô 1, cũng đúng nội dung nhưng sai điểm bắt đầu. Phương án "(3)" dồn r, l, d về các ô 0, 1, 2, ứng với việc nén hàng đợi về đầu mảng thay vì để đầu hàng trôi theo vòng.
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