Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

** In Java with detailed comments ** ** In Java with detailed comments ** Assign

ID: 3707035 • Letter: #

Question

** In Java with detailed comments **

** In Java with detailed comments **

Assignment 10 Take the code (it is from the Savitch student data files) listed here and 1) make it doubly linked 2) Add a copy constructor 3) Add a clone method 4) Replace outputList with toString 5) Code an iterator method 6) Keep track of the tail and add a method outputBackwards to prove the list is doubly linked Or use the Savitch code in the book for a doubly linked list and add the functionality mentioned above I think you will learn less that way but it is less work. To make the node doubly linked change to private Node link; private Node next; private Node prev Test all functionality by hard coding test cases into your demo file public class LinkedList3 linki public Node ) datanull linknull public Node (T newData, Node linkValue) data- newData; link 1inkValue //End of Node inner class private NodeT headi public LinkedList3 headnulli ?dds a node at the start of the list with the specified data The added node will be the first node in the list public void addToStart (T itemData) head- new Node?ítemData, head);

Explanation / Answer

/* * Java Program to Implement Doubly Linked List */ import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null; prev = null; data = 0; } /* Constructor */ public Node(int d, Node n, Node p) { data = d; next = n; prev = p; } /* Function to set link to next node */ public void setLinkNext(Node n) { next = n; } /* Function to set link to previous node */ public void setLinkPrev(Node p) { prev = p; } /* Funtion to get link to next node */ public Node getLinkNext() { return next; } /* Function to get link to previous node */ public Node getLinkPrev() { return prev; } /* Function to set data to node */ public void setData(int d) { data = d; } /* Function to get data from node */ public int getData() { return data; } } /* Class linkedList */ class linkedList { protected Node start; protected Node end ; public int size; /* Constructor */ public linkedList() { start = null; end = null; size = 0; } /* Function to check if list is empty */ public boolean isEmpty() { return start == null; } /* Function to get size of list */ public int getSize() { return size; } /* Function to insert element at begining */ public void insertAtStart(int val) { Node nptr = new Node(val, null, null); if(start == null) { start = nptr; end = start; } else { start.setLinkPrev(nptr); nptr.setLinkNext(start); start = nptr; } size++; } /* Function to insert element at end */ public void insertAtEnd(int val) { Node nptr = new Node(val, null, null); if(start == null) { start = nptr; end = start; } else { nptr.setLinkPrev(end); end.setLinkNext(nptr); end = nptr; } size++; } /* Function to insert element at position */ public void insertAtPos(int val , int pos) { Node nptr = new Node(val, null, null); if (pos == 1) { insertAtStart(val); return; } Node ptr = start; for (int i = 2; i list.getSize() ) System.out.println("Invalid position "); else list.insertAtPos(num, pos); break; case 4 : System.out.println("Enter position"); int p = scan.nextInt() ; if (p < 1 || p > list.getSize() ) System.out.println("Invalid position "); else list.deleteAtPos(p); break; case 5 : System.out.println("Empty status = "+ list.isEmpty()); break; case 6 : System.out.println("Size = "+ list.getSize() +" "); break; default : System.out.println("Wrong Entry "); break; } /* Display List */ list.display(); System.out.println(" Do you want to continue (Type y or n) "); ch = scan.next().charAt(0); } while (ch == 'Y'|| ch == 'y'); } }