Big Data and Hadoop Training @$80 or Rs. 6,000 only - valid till Oct 17th Apply Now!

How would I get this linked list in alphabetical order?

Ads
 

How would I get this linked list in alphabetical order?

import java.io.*; import java.util.Scanner;

public class LinkedList2 {

 public LinkedListNode head;
String fname;

public static void main(String[] args) throws FileNotFoundException{
        Scanner scan = new Scanner(new File("Names.txt"));
        LinkedList2 l = new LinkedList2();    
        int i = 1;
        while(scan.hasNext()) {
            String s = scan.nextLine();
            l.insertBack(s);
            i++;
        }
        System.out.print(l.showList());
    }

public void insertBack(String data){


    if(head == null){
        head = new LinkedListNode(data);
    }else{
        LinkedListNode newNode = new LinkedListNode(data);
        LinkedListNode current = head;
        while(current.getNext() != null){
            current = current.getNext();
        }
        current.setNext(newNode);
    }
}

public String showList(){
    int i = 0, j;
    String name = "List nodes:\n";
    LinkedListNode current = head;
    while(current != null){
        i++;
        name += "Node " + i + ": " + current.getData() + "\n";
        current = current.getNext();

    }

    return name;
}

}

this is the code that i have so far. i am able to read in the text file and print it out but i can get in in alphabetical order.

View Answers

Ads









Related Tutorials/Questions & Answers:
linked list
linked list
Advertisements
How to read bytes from a Linked list - Java Beginners
linked list
linked list
Linked List
linked list
Linked list
How would you read in and add all this into a list?
I would like an example about how to create a sessionfactory in Hibernate 4?
linked list
stack using linked list
HELP Generic linked list
How to create a Student data base using Linked List in java
Linked list implementation
how i can get jqfade.js library
Circular Linked List
How to index a given paragraph in alphabetical order
Explain Linked List
Doubly Linked List
about linked list
java linked list urgent!!!
java linked list urgent !!!
java linked list urgent !!!
java linked list urgent !!!
java linked list urgent !!!
java linked list urgent !!!
linked list in java - Java Beginners
How to get a list of MySQL user accounts?
Core java linked list example
Write a MoveFirst() for Circular Linked List

Ads