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

Write a Java program to demonstrate the use of linked-lists. The key to this des

ID: 3529691 • Letter: W

Question

Write a Java program to demonstrate the use of linked-lists. The key to this design is that the list will be ordered (sorted ascending) and will not contain duplicates. Your code will maintain this order. You will work with three file names provided (in the order below) on the command line: d4.dat d4.delete d4.out [or whatever you call it on the command line] Consider using the following LinkedList methods: boolean add(E e) boolean contains(Object o) boolean remove(Object o) Further, consider using the Collections.sort() method. The file d4.dat is here and d4.delete is here. You will produce an output file that contains all of d4.dat in sorted order, minus the duplicates and minus any items specified in d4.delete. Once you have processed the d4.dat file and the d4.delete file, it is a simple matter of iterating over the list and writing the object data to the outputfile. The output file size will be 22,725 or 27,270 bytes depending on platform and methods used.

Explanation / Answer

. import java.util.*;

class LinkedListDemo { public static void main(String args[]) { // create a linked list LinkedList ll = new LinkedList(); // add elements to the linked list ll.add("F"); ll.add("B"); ll.add("D"); ll.add("E"); ll.add("C"); ll.addLast("Z"); ll.addFirst("A"); ll.add(1, "A2");

System.out.println("Original contents of ll: " + ll);

// remove elements from the linked list ll.remove("F");

ll.remove(2);

System.out.println("Contents of ll after deletion: " + ll); // remove first and last elements ll.removeFirst(); ll.removeLast(); System.out.println("ll after deleting first and last: " + ll); // get and set a value Object val = ll.get(2); ll.set(2, (String) val + " Changed"); System.out.println("ll after change: " + ll); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote