Suppose a doubly linked list of integers is given below and p is a reference to the node with value 13 in the list (i.e. p.info=13): (head) 7 11 6 4 3 13 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
int x = 9;
Node q = new Node(x);
q.prev=null;
q.next = head;
head.prev = q;
head = q;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: "9 7 11 6 4 3 13 8 2". Điều đáng chú ý là đoạn mã không dùng tới p một lần nào: nó tạo q mang giá trị 9, đặt q.prev bằng null và q.next bằng head, rồi head.prev bằng q và head bằng q. Bốn lệnh ấy là khuôn chèn vào đầu danh sách liên kết đôi, nên 9 trở thành nút đầu đứng trước 7, còn mọi nút khác giữ đúng trật tự cũ. Vì vậy "7 11 6 4 3 13 8 2 9" sai vì nối vào cuối phải sửa tail.next và tail; "7 11 6 4 3 13 8 9 2" sai vì chèn trước nút cuối phải lấy mốc là tail.prev; "7 11 6 4 3 13 9 8 2" sai vì nó chèn ngay sau nút 13, đúng chỗ mà p trỏ tới, nhưng đoạn mã không hề đọc p; "7 9 11 6 4 3 13 8 2" sai vì chèn sau head thì q.next phải là head.next và head.next mới trỏ sang q, trong khi ở đây q.next chính là head.
Cùng phần 1
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?
Node p1,p2; p1 = p.next;
p2 = p1.next;
p.next = p2;
if(p2!=null) p2.prev=p;Có 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 13 in the list (i.e. p.info=13):
(head) 7 11 6 4 32 13 8 2 (tail)
What does the list look like after the following java code snippet is run?
int x = 17;
Node q = new Node(x);
q.prev=null;
q.next = head;
head.prev = q;
head = q;Có lời giảiCâu hỏiSelect 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ỏiCả 64 câu của chủ đề64 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây