Question: public class LLNode{ private Name name; private LLNode next; public LLNode(){ name=null; next=null; } public LLNode(Name name, LLNode next){ setName(name); setNext(next); } public Name getName(){

public class LLNode{

private Name name; private LLNode next; public LLNode(){ name=null; next=null; } public LLNode(Name name, LLNode next){ setName(name); setNext(next); }

public Name getName(){ return name; } public LLNode getNext(){ return next; } public void setName(Name name){ this.name = name; } public void setNext(LLNode next){ this.next = next; }

}

******************************************************************

public class Name implements Comparable{

private String firstName; private String lastName; public Name(String firstName, String lastName){ setFirstName(firstName); setLastName(lastName); }

public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public void setFirstName(String firstName){ this.firstName = firstName; } public void setLastName(String lastName){ this.lastName = lastName; } @Override public int compareTo(Name n){ String lastA = lastName.toUpperCase(); String firstA = firstName.toUpperCase(); String lastB = n.getLastName().toUpperCase(); String firstB = n.getFirstName().toUpperCase(); if(lastA.compareTo(lastB)==0){ return firstA.compareTo(firstB); } return lastA.compareTo(lastB); } @Override public String toString(){ return String.format("%15s%15s", firstName, lastName); } }

Please complete this code:

public class SortedNameList{ LLNode head; public SortedNameList(){ head=null; } public LLNode getHead(){ return head; } public boolean isEmpty(){ //return true if the list is empty, otherwise true /* Type your code here. */ } public void add(LLNode node){ //overloaded method: add node to the list, after this operation, the list should maintain sorted in ascending order /* Type your code here. */ }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!