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 "How***areyou***"?
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: "(1)". Đó là mảng có y ở ô 0, o ở ô 1, u ở ô 2, ba ô còn lại trống. Mảng vòng sáu ô: nạp H vào ô 0, o vào ô 1, w vào ô 2; ba dấu sao lấy ra cả ba nên hàng đợi rỗng, nhưng con trỏ cuối vẫn đứng sau ô 2 vì phép lấy ra chỉ nhích con trỏ đầu. Nạp tiếp a vào ô 3, r vào ô 4, e vào ô 5, rồi y quay vòng về ô 0, o vào ô 1, u vào ô 2. Ba dấu sao cuối lấy ra a, r, e, nên chỉ còn y, o, u ở ô 0, ô 1, ô 2. Mảng "(2)" đặt y, o, u ở ô 1 tới ô 3, muốn vậy a phải vào ô 4, nghĩa là ba ký tự đầu đã chiếm ô 1 tới ô 3 thay vì ô 0 tới ô 2. Mảng "(3)" đặt y ở ô 4, o ở ô 5, u ở ô 0, tức a vào ô 1 nên cả khối lệch một ô. Mảng "(4)" đặt y ở ô 5, o ở ô 0, u ở ô 1, tức a vào ô 2 nên khối lệch hai ô so với ô 3 mà con trỏ cuối đang chỉ tới.
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