I'm trying to sort the Linked List by the key( priority number, the int number) from highest to lowest, with the data from text file. I'm stucking at insert the item and sort them.
Here is My text file.

Myjob 66

Junk 17

Fun 25

Important 96

Vital 99

MoreFun 28

Work 69

Assignment 44

Here is my Linked List class

```
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

@SuppressWarnings("unused")
public class LinkedList {
    Node head;
    Node prev;
    Node cur;
    Node node;

public LinkedList(){

}

public LinkedList(Node head){
    head = null;
}

//getter to get head
public Node gethead(){
    return head;
}

//insert method
public void insert(Data dt){
    try {
        if(head==null){
            head = new Node(dt.getData(), null);
            System.out.println("Opps");
            }
        else if (dt.getData().num > head.dt.num){
            head = new Node(dt.getData(),head);
            System.out.println("Was Here");}
        else if (head.getNext()==null){
            head.setNext(new Node(dt.getData(),null));
            }
        else{
            cur = head.getNext();
            for(prev = head;cur!= null;cur=cur.getNext()){
                if(cur.dt.num>prev.dt.num){
                    Node temp = new Node(dt.getData(),cur);
                    prev.setNext(temp);
                    break;
                }
                else{
                    prev=cur;

                }
            }
        }
    }
        catch (NullPointerException e){
            System.out.println("Here is Error");
        }

}

//Running Linked list
public static void main(String[] args) throws FileNotFoundException{

        LinkedList l1 = new LinkedList();
        Data dt = new Data();

        l1.insert(dt);

}

```

}

Here is My Node class:

```
public class Node {
Data dt;
Node next;

public Node(Data dt, Node next){
    this.dt=dt;
    this.next=next;
}

public Node getNext(){
    return next;
}

public void setNext(Node next){
    this.next=next;
}

public Data getData(){
    return dt.getData();
}

}

```

Here is my Data class:

```
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Data {

protected String name;
protected int num;

public Data(){
}

public Data(String name,int num){
    this.name=name;
    this.num=num;
}

//getter to get Data
@SuppressWarnings("unused")
public Data getData(){
        try{
            int count =0;
            File x = new File("Asg2Data.txt");
            Scanner sc = new Scanner(x);
            while (sc.hasNext()){
                String name = sc.next();
                int num = sc.nextInt();
                Data data= new Data(name,num);
                System.out.println("Name = "+ name+"          "+"Priority = "+num);
                System.out.println(" ");
                count++;
            }
            System.out.println("Total Objects: "+count);
            sc.close();
        }catch(FileNotFoundException e){
            System.out.println("Error");
        }
        return this;
}

//Compare Function
//  public int compare(Data dt){
//      if (this.getData().num > dt.getData().num)
//          return 1;
//      else if (this.getData().num < dt.getData().num)
//          return -1;
//      else
//          return 0;
//  }

// Testing: Worked !!!!!    
    public static void main(String[] args){
        Data d1 = new Data();
        d1.getData();
    }

}

```

My currently output, when I run from Linked List class:

```
Name = Myjob          Priority = 66

Name = Junk          Priority = 17

Name = Fun          Priority = 25

Name = Important          Priority = 96

Name = Vital          Priority = 99

Name = MoreFun          Priority = 28

Name = Work          Priority = 69

Name = Assignment          Priority = 44

Total Objects: 8
Opps

```

My insert method always stop at the first if statement, and never keep going. I have no clue how to fix it. At the mean time, it can not perform the insert the data + sort them by the priority number from highest to lowest. Can anyone help me ? I'm super new in Java. Thank you so much.

-Dustin