I need to implement a singly linked list in ascending order without using any of the Java built-in Collection classes. The data value in the node is a Book object and the sorting is based on the title, or author's first or author's last name. The sorting is based on user's input (1:title, 2:first name, 3:last name). My Driver file needs to read books' information from a Book.dat file and each line of the file is in the format of "BookTitle@LastName@FirstName"
The linked list class also needs to include methods to return the size of the linked list, print the linked list, test if x is contained in the linked list, add a value x if it is not already in the linked list, and remove a value s if it is contained in the linked list.
I am really stumped on this problem!
import java.util.*; import java.io.*; public class ListOfBooks { public static void main(String [] args){ try{ BufferedReader reader = new BufferedReader(new FileReader ("database.txt")); String line = reader.readLine(); Node front = null; Node back = null; while(line != null){ String book = line; line = reader.readLine(); } Node n = new Node(); n.data = line; if (front == null){ front = n; } else { back.next = n; } back = n; } catch (IOException ioe){ System.out.println("I/O Exception error"); Node curr; curr = front; while (curr != null){ System.out.println(curr.data); curr = curr.next; } } } class Node{ public Node next; public String data; } }
I need to implement a singly linked list in ascending order without using any of the Java built-in Collection classes. The data value in the node is a Book object and the sorting is based on the title, or author's first or author's last name. The sorting is based on user's input (1:title, 2:first name, 3:last name). My Driver file needs to read books' information from a Book.dat file and each line of the file is in the format of "BookTitle@LastName@FirstName"
The linked list class also needs to include methods to return the size of the linked list, print the linked list, test if x is contained in the linked list, add a value x if it is not already in the linked list, and remove a value s if it is contained in the linked list