Suppose a doubly linked list of integers is given below and p is a reference to the node with value 29 in the
5 phương ánCó giải thích
list (i.e. p.info=29):(head) 17 11 6 4 3 29 8 2 (tail) What does the list look like after the following java code snippet is run?
int x = 5;
Node p1, p2;
p1 = new Node(x);
p2 = p.next;
p.next = p1; p1.prev = p;
p1.next = p2; p2.prev = p1;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: "17 11 6 4 3 29 5 8 2". Danh sách đôi là 17, 11, 6, 4, 3, 29, 8, 2 và p trỏ vào nút 29. Mã tạo p1 giữ giá trị x = 5, lấy p2 = p.next là nút 8, rồi nối p.next = p1 cùng p1.prev = p để 5 đứng ngay sau 29, tiếp đó p1.next = p2 cùng p2.prev = p1 để 5 nối tiếp sang 8 ở cả hai chiều. Nút 5 do đó nằm giữa 29 và 8. Phương án "17 11 6 4 3 5 29 8 2" là chèn trước nút 29, muốn vậy phải nối qua p.prev chứ không qua p.next. Phương án "17 11 6 4 3 29 8 2 5" là chèn vào cuối, cần dùng tail và gán tail = p1. Phương án "17 5 11 6 4 3 29 8 2" chèn ngay sau head, không liên quan tới p. Phương án "5 17 11 6 4 3 29 8 2" chèn vào đầu, đòi gán lại head mà mã không làm.
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