// Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved. /** Implementation file for the class SortedListIsA. @file SortedListIsA.cpp */ #include "SortedListIsA.h" // Header file #include #include template SortedListIsA::SortedListIsA() { } // end default constructor template SortedListIsA::SortedListIsA(const SortedListIsA& sList) : LinkedList(sList) { } // end copy constructor template SortedListIsA::~SortedListIsA() { } // end destructor template void SortedListIsA::insertSorted(const ItemType& newEntry) { int newPosition = fabs(getPosition(newEntry)); // We need to call the LinkedList version here since the // SortedListIsA version does nothing but return false LinkedList::insert(newPosition, newEntry); // this->insert(newPosition, newEntry); // WRONG as it calls the overriding version } // end insertSorted template bool SortedListIsA::removeSorted(const ItemType& anEntry) { bool ableToRemove = false; if (!LinkedList::isEmpty()) { int position = getPosition(anEntry); ableToRemove = position > 0; if (ableToRemove) { ableToRemove = LinkedList::remove(position); } // end if } // end if return ableToRemove; } // end removeSorted template int SortedListIsA::getPosition(const ItemType& anEntry) const { int position = 1; int length = LinkedList::getLength(); while ( (position <= length) && (anEntry > LinkedList::getEntry(position)) ) { position++; } // end while if ( (position > length) || (anEntry != LinkedList::getEntry(position)) ) { position = -position; } // end if return position; } // end getPosition template bool SortedListIsA::insert(int newPosition, const ItemType& newEntry) { return false; } // end insert template void SortedListIsA::setEntry(int position, const ItemType& newEntry) throw(PrecondViolatedExcep) { throw PrecondViolatedExcep("This is an illegal action!"); } // end setEntry // End of implementation file.