public void remove(OrderedLinkedList objToRemove) { OrderedLinkedList eval = this; do { if (eval.next == null) { return; //can't do anything since not found the one that does match the one to be removed. } eval = eval.next; } while (eval.Equals(objToRemove) == false); if (eval.Equals(objToRemove)) { //need to know whom points to me...(this instance) // or can overwrite my value with the next and remove the next. if (eval.next == null) { eval = null; //get rid of this... } else { eval.value = eval.next.value; eval.next = eval.next.next; } } }
private void swap(OrderedLinkedList obj1, OrderedLinkedList obj2) { if (obj1.Equals(this)) { if (obj1.next != null) //if cat has a next { OrderedLinkedList temp = new OrderedLinkedList(this.value); this.value = obj2.value; OrderedLinkedList temp2 = this.next; this.next = temp; temp.next = temp2; } else //no next { OrderedLinkedList temp = new OrderedLinkedList(this.value); this.value = obj2.value; this.next = obj2; } } else { OrderedLinkedList temp = new OrderedLinkedList(obj1.value); obj1.value = obj2.value; temp.next = obj1.next; obj1.next = temp; } }