Suppose 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 1 6 4 3 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 1 6 4 3 9 2". Với p trỏ vào nút 9, p1 nhận nút kế tiếp là 8 và p2 nhận nút sau nữa là 2. Hai lệnh còn lại nối trực tiếp 9 với 2 theo cả hai chiều: p.next = p2 cho 9 trỏ tới 2, p2.prev = p cho 2 trỏ lùi về 9. Nút 8 không còn ai trỏ tới nên bị tách khỏi danh sách, kết quả là 7 1 6 4 3 9 2. "7 1 6 4 3 9 8" cắt mất nút 2 ở cuối, nhưng 2 đã được giữ qua p2 và được nối lại ngay. "7 1 6 4 3 8 2" xoá nút 9, trong khi 9 chính là nút p dùng làm điểm tựa và không hề bị bỏ liên kết. "7 1 6 4 9 8 2" xoá nút 3 đứng trước p, nhưng đoạn mã không chạm tới p.prev. "1 6 4 3 9 8 2" xoá nút đầu danh sách, điều chỉ xảy ra nếu có lệnh gán lại 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