Consider the following pseudocode: declare a queue 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 dequeue and write the dequeued character to the screen
else
enqueue the character into the queue
}What is written to the screen for the input ""Go*odA**fter****Noo***n" ?
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: "GoodAfterN". Hàng đợi lấy ra phần tử vào sớm nhất, nên mỗi dấu sao in ra một ký tự theo đúng thứ tự nạp vào. Lần lượt: G và o vào, dấu sao in G; o, d, A vào, hai dấu sao in o rồi o; f, t, e, r vào, bốn dấu sao in d, A, f, t; N, o, o vào, ba dấu sao in e, r, N; cuối cùng n vào mà không còn dấu sao nào. Những ký tự được in là G, o, o, d, A, f, t, e, r, N, tức GoodAfterN, còn o, o, n vẫn nằm trong hàng đợi. Dãy "GoodAfter" dừng sớm một ký tự, bỏ sót chữ N do dấu sao thứ ba của nhóm sau Noo in ra. Dãy "oodAfteroo" mất chữ G ở đầu, nhưng G vào sớm nhất nên phải là ký tự đầu tiên bị lấy ra. Dãy "oAdoretfoo" in ký tự mới vào trước ký tự cũ, đó là hành vi vào sau ra trước của ngăn xếp, không phải của hàng đợ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