/** * */ package zhstructures; /** * @author jholey * */ public class ZHLinkedSortedList> extends ZHOneWayLinkedStructure> implements ZHSortedList { /** * */ public ZHLinkedSortedList() { super(); } /** * @param element * @param next */ protected ZHLinkedSortedList(ElementType element, ZHLinkedSortedList next) { super(element, next); } /* (non-Javadoc) * @see zhstructures.ZHSortedList#add(java.lang.Comparable) */ @Override public boolean add(ElementType element) { if (this.isEmpty()) { this.element = element; this.next = new ZHLinkedSortedList(); this.state = ZHComponentState.NOT_EMPTY; return true; } int comp = element.compareTo(this.element); if (comp < 0) { this.next = new ZHLinkedSortedList(this.element, this.next); this.element = element; return true; } else if (comp == 0) { return false; } else { return this.next.add(element); } } /* (non-Javadoc) * @see zhstructures.ZHOneWayLinkedStructure#contains(java.lang.Object) */ @Override public boolean contains(ElementType element) { if (this.isEmpty()) return false; int comp = element.compareTo(this.element); if (comp < 0) { return false; } else if (comp == 0) { return true; } else { return this.next.contains(element); } } /* (non-Javadoc) * @see zhstructures.ZHSortedList#remove(java.lang.Comparable) */ @Override public boolean remove(ElementType element) { if (this.isEmpty()) return false; int comp = element.compareTo(this.element); if (comp < 0) { return false; } else if (comp == 0) { this.element = this.next.element; this.state = this.next.state; this.next = this.next.next; return true; } else { return this.next.remove(element); } } }