Select the statement that is most correct. Suppose we are considering a doubly linked list and p is some node in the list which has successor node. What does the java code snippet below do?
4 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: "It deletes the node after p.". Đoạn mã lấy p1 = p.next là nút liền sau p, rồi p2 = p1.next là nút sau nữa; lệnh p.next = p2 cho p trỏ vượt qua p1, và p2.prev = p vá chiều ngược lại khi p2 còn tồn tại. Sau hai phép gán đó không còn liên kết nào chỉ vào p1, nên nút liền sau p bị loại; phép kiểm tra p2 != null chỉ để tránh truy cập prev của null trong trường hợp p1 là nút cuối. Phương án "It deletes the node p." sai vì p vẫn nằm trong danh sách và còn là nơi phát ra liên kết mới. Phương án "It deletes the node before p." sai vì mã không đọc cũng không gán p.prev, nên phía trước p không hề thay đổi. Phương án "It does not make any change on the list." sai vì p.next bị trỏ sang nút cách hai bước, làm danh sách ngắn đi đúng một nút.
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