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 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<Name>{
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);
}
}
******************************************************************
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(Name name){
//add name to the list, after this operation, the list should maintain sorted in ascending order
/* 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. */
}
public int size(){
//return the number of nodes in the list
/* Type your code here. */
return 0; // replace with yours
}
public boolean isFull(){
return false;
}
public int search(Name name){
//return index of the name (the first occurrence) in the list, return -1 if not found
/* Type your code here. */
return -10; // replace with yours
}
public LLNode get(int index){
// return the LLNode object at the specified index location, for invalid index, return null
/* Type your code here. */
return new LLNode(new Name("a","b"), null); //replace with yours
}
public void remove(int index){
//Remove node at the specified index location if valid.
/* Type your code here. */
}
public void remove(Name name){
//remove all occurences of name - please refer to Name class for details
/* Type your code here. */
}
public void removeAll(){
//remove all nodes
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps