Exercise 3 - Doubly Linked Lists 1. Open Double LinkedNode.java and BuildDLL.java in Eclipse and examine the code in bot

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Exercise 3 - Doubly Linked Lists 1. Open Double LinkedNode.java and BuildDLL.java in Eclipse and examine the code in bot

Post by answerhappygod »

Exercise 3 Doubly Linked Lists 1 Open Double Linkednode Java And Builddll Java In Eclipse And Examine The Code In Bot 1
Exercise 3 Doubly Linked Lists 1 Open Double Linkednode Java And Builddll Java In Eclipse And Examine The Code In Bot 1 (215.01 KiB) Viewed 54 times
public class DoubleLinkedNode<E> {
private DoubleLinkedNode<E> next; private DoubleLinkedNode<E>previous; private E element;
public DoubleLinkedNode(){ next = null; previous = null; element = null; }
public DoubleLinkedNode (E elem){ next = null; previous = null; element = elem; }
public DoubleLinkedNode<E>getNext(){ return next; }
public DoubleLinkedNode<E>getPrevious(){ return previous; }
public void setNext(DoubleLinkedNode<E> node){ next = node; }
public void setPrevious(DoubleLinkedNode<E> node){ previous = node; }
public E getElement(){ return element; }
public void setElement (E elem){ element = elem; }
}
-------------
public class BuildDLL { DoubleLinkedNode<Character> front,rear; private static char[] letters = new char[] {'K','T', 'E', 'N', 'P', 'A', 'L'};
public BuildDLL () { build(); }
public void remove (Character elem) { // Add code in here to removethe node with the given value.
} private void build () { DoubleLinkedNode<Character> pnode, node; node = newDoubleLinkedNode<Character>(letters[0]); pnode = front = node; for (int i = 1; i < 7;i++) { node = newDoubleLinkedNode<Character>(letters); pnode.setNext(node); node.setPrevious(pnode); pnode =node; } rear = node; } public DoubleLinkedNode<Character>getFront () { return front; } public DoubleLinkedNode<Character> getRear() { return rear; } public void printF(DoubleLinkedNode<Character> node) { DoubleLinkedNode<Character> curr = front; while (curr != null) { System.out.print(curr.getElement() + " "); curr =curr.getNext(); } System.out.print("\n"); } public static void main (String[] args) { BuildDLL dll = newBuildDLL();
System.out.println("Original List:"); dll.printF(dll.getFront()); System.out.println("***"); System.out.println("Removingan internal node:"); dll.remove('N'); dll.printF(dll.getFront()); System.out.println("***"); System.out.println("Removingthe front node:"); dll.remove('K'); dll.printF(dll.getFront()); System.out.println("***"); System.out.println("Removingthe rear node:"); dll.remove('L'); dll.printF(dll.getFront()); System.out.println("***"); }
}
Exercise 3 - Doubly Linked Lists 1. Open Double LinkedNode.java and BuildDLL.java in Eclipse and examine the code in both classes. 2. The Double LinkedNode class is complete and does not have to be modified. 3. The BuildDLL class has some provided methods for creating a doubly linked list with a sequence of letters (note that we are using the Character class for this, which is a wrapper for the primitive char type) and printing out the list from front to rear. Run the program to see the default output. 4. Notice that the original list is printing correctly, but the remove() method is not provided so subsequent list outputs are incorrect. 5. You must fill in the code for removing an element from the linked list using the following rules and hints:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply