public class ConeList { ConeNode head_; ConeNode iterator_; ConeNode prev_; public ConeList() { head_ = null; } public ConeList(ConeNode head) { head_ = head; } public boolean insertCone(ConeNode cone) { if (head_ == null) { head_ = cone; return true; } iterator_ = head_; prev_ = iterator_; // it's sorted...find out where to put it // searchForCone should be able to tell where it should be (?) if (iterator_.getNext() == null && iterator_.isEqualTo(cone) == ConeNode.GREATER) { head_ = cone; head_.setNext(iterator_); } else { while (iterator_ != null && iterator_.isEqualTo(cone) == ConeNode.LESS) { // iterator_.printCone(); prev_ = iterator_; iterator_ = iterator_.getNext(); // System.out.println("p: " + prev_); } // iterator should be at the point where the new cone should be inserted // prev's next should be cone, cone's next should be iterator // System.out.println("i: " + iterator_); // System.out.println("h: " + head_); // System.out.println("p: " + cone); prev_.setNext(cone); cone.setNext(iterator_); } // when does it return false? how do we know if it's unsuccesful return true; } public boolean searchFor(ConeNode cone) { if (head_ == null) { System.out.println("head is null"); return false; } iterator_ = head_; // search for cone System.out.println("cone to be searched for:"); cone.printCone(); while (iterator_ != null && iterator_.isEqualTo(cone) == ConeNode.LESS) { prev_ = iterator_; iterator_.printCone(); iterator_ = iterator_.getNext(); } int test = iterator_.isEqualTo(cone); System.out.println(test); if (prev_ == null) { while (iterator_ != null) { prev_ = iterator_; iterator_.printCone(); iterator_ = iterator_.getNext(); } } return (test == ConeNode.EQUAL); } public boolean deleteCone(ConeNode cone) { if (head_ == null) { return false; } iterator_ = head_; // search for cone, delete it; successful delete = true, unsuccessfull = false while (iterator_ != null && iterator_.isEqualTo(cone) == ConeNode.LESS) { prev_ = iterator_; iterator_ = iterator_.getNext(); } // iterator should point to the one to be deleted; // set iterator's next to null // set prev's next to null // what if it doesn't find it? iterator_.setNext(null); prev_.setNext(null); return false; } }