guys, I have the following method (add), and as I'm adding values to the list I need to order in ascending order based on firstNmae+" "+lastName. I tried using the Collections.sort(students) in the main method, but that doesn't work, besides I need to come up with an implementation that compares new data name to the rest of list names( I think that is the right algorithm)
public class LinkedList { private Node first; public LinkedList() { this.first = null; } //add students to the list public void add(Student s) { Node newNode = new Node(s); newNode.next = first; first = newNode; } //remove duplicate records (return true if duplicate found) // public boolean remove(String fn, String ln) // { // // } //display list of student public void display() { if(first == null) System.out.println("List is empty!"); else { System.out.println(first.value); first = first.next; } } }
public class Tester { public static void main(String[] args) { UnderGrad john = new UnderGrad("john", "doe", 2.7, "computer Science", "phisics"); UnderGrad jorge = new UnderGrad("jorge", "vazquez", 3.8, "computer Science", "programming"); Advisor jim = new Advisor("jim", "smith"); Grad jane = new Grad("jane", "doe", 3.0, "Electric Engineering", jim); LinkedList students = new LinkedList(); students.add(john); students.add(jorge); students.add(jane); students.display(); } }