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 "Goo**dMor***ning**"?
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òn n ở ô 1, i ở ô 2, n ở ô 3 và g ở ô 4, hai ô 0 và 5 trống. Đếm trước cho nhanh: dãy nhập có mười một chữ cái và bảy dấu sao, nên hàng đợi còn đúng bốn phần tử, và vì dequeue chỉ lấy ở đầu nên bốn phần tử sót lại phải là bốn chữ vào sau cùng, theo thứ tự n, i, n, g. Vị trí thì chạy tay: G, o, o nằm ô 0, 1, 2; d, M, o nằm ô 3, 4, 5; r quay vòng về ô 0; rồi n, i, n, g lần lượt vào ô 1, 2, 3, 4; bảy lần dequeue đẩy đầu hàng từ ô 0 tới ô 1. "(1)" sai vì nội dung i, n, g, o của nó giữ lại chữ o của cụm Mor vốn đã bị dequeue và làm mất chữ n đầu của cụm ning. "(2)" sai vì cùng nội dung i, n, g, o lại còn đặt đầu hàng ở ô 0, trong khi bảy lần dequeue tính từ ô 0 phải đưa đầu hàng về ô 1. "(3)" sai vì vẫn là i, n, g, o xếp liền từ ô 1, tức đếm thiếu một lần enqueue so với dãy nhập.
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