You are given a singly linked list with at least 3 elements and p is a reference to a middle node (p is not the head nor the tail node). Select the statement about deleting the node p from the list that is most correct.
4 phương ánCó giải thích
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: "We can delete the node p by moving the data from the next node into the p node and then deleting the next node by statement p.next = p.next.next; This solution has O(1) runtime.". Trong danh sách liên kết đơn ta không lùi được, nhưng không nhất thiết phải giải phóng đúng ô nhớ của p: chép dữ liệu của nút kế tiếp vào p rồi tháo nút kế tiếp ra bằng p.next = p.next.next là đã cho đúng dãy giá trị cần có, và vì p không phải tail nên p.next luôn tồn tại; toàn bộ gói trong vài phép gán nên là O(1). Phương án "We can find the node f before the node p and then deleting the node p by statement f.next = p.next; This solution has O(1) runtime." sửa liên kết đúng nhưng ước lượng sai chi phí: tìm f phải đi từ head nên mất O(n). Phương án "Deleting the node p always takes O(n) time." bị chữ always phá bởi đúng mẹo chép dữ liệu nói trên. Phương án "Deleting the node p always takes O(1) time." sai theo chiều ngược lại: nếu p là nút cuối thì không có nút kế tiếp để chép, buộc phải đi tìm nút trước nó, nên không phải lúc nào cũng O(1).
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