public class NameList {

  private String name;
  private NameList next;

  public NameList(String name) {
    this.name = name;
    this.next = null;
  }

  public NameList insert(NameList node) {
    if (node.getName().compareTo(name) < 0) {
      node.setNext(this);
      return node;
    }
    else if (next == null) {
      this.next = node;
      return this;
    }
    else {
      next = next.insert(node);
      return this;
    }
  }

  public NameList get(String name) {
    if (name.equals(this.name))
      return this;
    else if (next == null)
      return null;
    else
      return next.get(name);
  }

  public NameList delete(String name) {
    if (name.equals(this.name))
      return next;
    else if (next == null)
      return this;
    else {
      next = next.delete(name);
      return this;
    }
  }

  public void setNext(NameList next) {
    this.next = next;
  }

  public String getName() {
    return name;
  }

  public NameList getNext() {
    return next;
  }

}
