Question
1. Explain the code below (a) public void insertFront(Object item) { DListNode newNode = newNode(item, head, head.next); head.next.prev = newNode; head.next = newNode; size ++;
1. Explain the code below
(a) public void insertFront(Object item) { DListNode newNode = newNode(item, head, head.next); head.next.prev = newNode; head.next = newNode; size ++; } explain your design:
(b) public void insertBack(Object item) { DListNode newNode = newNode(item, head.prev, head); head.prev.next = newNode; head.prev = newNode; size ++; } explain your design:
(c) public DListNode front() { if(size != 0) { return head.next; } else { return null; } } explain your design:
(d) public DListNode back() { if(size != 0) { return head.prev; } else { return null; } } explain your design:
(e) public DListNode prev(DListNode node) { if( node == null || node.prev == head ) { return null; } else { return node.prev; } } explain your design:
(f) public DListNode next(DListNode node) { if( node == null || node.next == head) { return null; } else { return node.next; } } explain your design:
(g) public void insertAfter(Object item, DListNode node) { if(node != null) { DListNode insAfter_Node = newNode(item, node, node.next); node.next.prev = insAfter_Node; node.next = insAfter_Node; size ++; } } explain your design:
(h) public void insertBefore(Object item, DListNode node) { if(node != null) { DListNode insBefore_Node = newNode(item, node.prev, node); node.prev.next = insBefore_Node; node.prev = insBefore_Node; size ++; } } explain your design:
(i) public void remove(DListNode node) { node.prev.next = node.next; node.next.prev = node.prev; size --; } explain your design:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started