How would I get this linked list in alphabetical order?

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









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
Linked list
Linked List
linked list
linked list
How would I learn data science if I started over?
How to read bytes from a Linked list - Java Beginners
How would you read in and add all this into a list?
linked list
I would like an example about how to create a sessionfactory in Hibernate 4?
stack using linked list
HELP Generic linked list
Linked list implementation
How to create a Student data base using Linked List in java
Explain Linked List
about linked list
ModuleNotFoundError: No module named 'linked_list'
Circular 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
Write a MoveFirst() for Circular Linked List
Doubly Linked List
Core java linked list example
How to index a given paragraph in alphabetical order
ModuleNotFoundError: No module named 'doubly_linked_list'
ModuleNotFoundError: No module named 'linked_list_mod'
ModuleNotFoundError: No module named 'another-linked-list'
ModuleNotFoundError: No module named 'doubly_linked_list'
how i can get jqfade.js library
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?
Queue implementation using linked list.
Overview of Linked List
How do I get started with Bootstrap
How do I get started with Bootstrap
Issue with tutorial realted to insertion in middle in Linked List
Singly Linked List
creating java linked list - Java Beginners
delete a node from singly linked list in java

Ads