Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions