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:
How would I get this linked list in alphabetical order?
How can I get experience in data science if no one would hire me?
Advertisements
linked list
linked list
linked list
How would I learn data science if I started over?
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 i can get jqfade.js library
How to create a Student data base using Linked List in java
Linked list implementation
How can I get into big data?
How do I get a job in AI?
How can I get IBM certification for free?
How do I get a job in AI field?
How do I get started with Bootstrap
How do I get started with Bootstrap
How to index a given paragraph in alphabetical order
about linked list
ModuleNotFoundError: No module named 'linked_list'
java linked list urgent!!!
java linked list urgent !!!
java linked list urgent !!!
java linked list urgent !!!

Ads