Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Singly Linked List

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Singly Linked List

    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
    Last edited by helloworld922; September 27th, 2012 at 02:41 PM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,884
    Thanks
    55
    Thanked 2,348 Times in 2,319 Posts

    Default Re: Singly Linked List

    Can you explain what problems you are having? Make a list of the problems and work through the list one item at a time.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Singly-Linked list structure
    By blaster in forum Algorithms & Recursion
    Replies: 24
    Last Post: March 11th, 2012, 04:42 PM
  2. Singly Circular Linked List Error
    By clydefrog in forum Collections and Generics
    Replies: 7
    Last Post: March 5th, 2012, 08:17 PM
  3. Linked list Schminked list help with Nodes Please
    By Bially in forum Collections and Generics
    Replies: 1
    Last Post: September 29th, 2011, 04:20 PM
  4. Singly Linked List of Integers, get(int i) function throws Null Pointer Exception
    By felixtum2010 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 23rd, 2011, 07:55 PM
  5. linked list help
    By tjoney in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 3rd, 2011, 06:54 PM

Tags for this Thread