Tất cả câu hỏi
Ngân hàng câu hỏi trắc nghiệm có giải thích chi tiết.
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***"?
void fun(int n)
{if (n <= 0)
System.out.println("That's all!");
else
{for(int i = 1; i <= n; i++)
System.out.print("*");
System.out.println( );
fun(n - 2);
}
}What is the output when the statement fun(5); is run?
That's all!
*****
***
******
***
*
That's all!****
**
*
That's all!*
***
*****
That's all!In a binary search tree, all the nodes that are left descendants of node A have key values greater than A; all
the nodes that are A's right descendants have key values less than (or equal to) A.void fun(int n)
{if (n < 0)
{System.out.println(“-“);
fun(-n);
}
else if(n<10)
System.out.println(n);
else
{fun(n/10);
System.out.println(n%10);
}
}Which call will result in the most recursive calls?
fun(1023);fun(100);fun(0);fun(-1023);int x = 5;
Node f = head;
while(f.next != tail) f = f.next;
Node q = new Node(x);
q.next = tail;
f.next = q;for i := 1 to n-1
insert a[i] into sorted sublist {a[0],...,a[i-1]}
so that the sortedness is still kept.
end forSelect the most correct solution: Consider the list of ten integers below: 17, 5, 3, 11, 10, 8, 13, 4, 8, 6 What is the list after the FIRST TWO steps of insertion sort? (sorting from smallest to largest).
Node q = new Node(x);
q.next = null;tail.next = new Node(x);
tail.next = null;
tail = tail.next;Node q = new Node(x);
q.next = null;
tail.next = q;
tail = q;tail.next = new Node(x);
tail.next.next = null;Đáp án đúng: "Node q = new Node(x); q.next = null; tail.next = q; tail = q;". Chèn vào cuối danh sách liên kết đơn cần đủ ba việc: tạo nút mới với next là null để nó thực sự là nút cuối, cho nút cuối hiện tại trỏ tới nó, và cập nhật tail để biến này tiếp tục chỉ đúng nút cuối. Đoạn mã này làm cả ba theo thứ tự an toàn vì nó gắn q vào sau tail cũ trước khi đổi tail. Phương án "Node q = new Node(x); q.next = null;" chỉ tạo nút rồi bỏ đó, không nút nào trong danh sách trỏ tới q nên danh sách không dài thêm. Phương án "tail.next = new Node(x); tail.next = null; tail = tail.next;" gán tail.next hai lần, lần sau ghi null lên chính liên kết vừa tạo nên nút mới bị mất, rồi tail nhận null và không còn chỉ vào nút nào. Phương án "tail.next = new Node(x); tail.next.next = null;" gắn được nút mới nhưng quên cập nhật tail, nên lần chèn sau lại gắn vào nút kề cuối và ghi đè mất nút vừa thêm.