Given main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing the insertInDescendingOrder() method to insert new IntNodes into the IntList in descending order.
Ex. If the input is:
3 4 2 5 1 6 7 9 8 -1
the output is:
9 8 7 6 5 4 3 2 1
import java.util.Scanner;
public class SortedList {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
IntList intList = new IntList();
IntNode curNode;
int num;
num = scnr.nextInt();
while (num != -1) {
// Insert into linked list in descending order
curNode = new IntNode(num);
intList.insertInDescendingOrder(curNode);
num = scnr.nextInt();
}
intList.printIntList();
}
}
