Suppose a doubly linked list of integers is given below and p is a reference to the node with value 30 in the list (i.e. p.info=30): (head) 7 11 6 4 30 9 8 2 (tail) What does the list look like after the following java code snippet is run?
5 phương ánCó giải thích
Node p1,p2; p1 = p.next;
p2 = p1.next;
p.next = p2;
if(p2!=null) p2.prev=p;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: "7 11 6 4 30 8 2". Đoạn mã chỉ nối lại con trỏ chứ không cấp phát nút mới: p trỏ vào nút 30 nên p1 = p.next là nút 9 và p2 = p1.next là nút 8; lệnh p.next = p2 cho nút 30 trỏ thẳng sang 8, còn p2.prev = p cho 8 quay lại 30, nên nút 9 không còn ai trỏ tới và rơi khỏi danh sách, để lại 7 11 6 4 30 8 2. Dãy "7 11 6 30 9 8 2" xoá nút 4 đứng trước 30, muốn vậy phải sửa p.prev chứ không phải p.next. Dãy "7 11 6 4 30 9 2" xoá nút 8, tức bỏ chính p2, muốn vậy phải gán p1.next = p2.next. Dãy "7 11 4 30 9 8 2" xoá nút 6, cách 30 hai bước về phía đầu, vùng mà đoạn mã không hề chạm tới. Dãy "11 6 4 30 9 8 2" xoá nút đầu 7, muốn vậy phải dịch chính biến head.
Cùng phần 1
Select the statement that is most correct.
Basically, the complexity of getting an element at the middle of a singly linked lists isCó lời giảiCâu hỏiSuppose a doubly linked list of integers is given below and p is a reference to the node with value 9 in the list (i.e. p.info=9):
(head) 7 11 6 4 3 9 8 12 (tail)
What does the list look like after the following java code snippet is run?
int x = 5;
Node f = p.prev; // prev is a link to predecessor node
Node q = new Node(x); // Create new node with value x
q.prev = f; q.next = p;
f.next = q; p.prev = q;Có lời giảiCâu hỏiSelect the statement that is most correct.
Suppose we are considering a singly linked list which has at least 2 nodes. What does the java code snippet below do?
Node f = head;
while(f.next != tail) f = f.next;
f.next = null;
tail = f;Có lời giảiCâu hỏiCả 64 câu của chủ đề64 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây