Source of Listing12-4.h


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: // Listing 12-4.

  6: /** ADT sorted list using ADT list.
  7:  @file SortedListIsA.h */
  8: #ifndef SORTED_LIST_IS_A_
  9: #define SORTED_LIST_IS_A_
 10: #include <memory>
 11: #include "LinkedList.h"
 12: #include "Node.h"
 13: #include "PrecondViolatedExcept.h"

 15: template<class ItemType>
 16: class SortedListIsA : public LinkedList<ItemType>
 17: {
 18: public:
 19:    SortedListIsA();
 20:    SortedListIsA(const SortedListIsA<ItemType>& sList);
 21:    virtual ~SortedListIsA();
 22:    
 23:    bool insertSorted(const ItemType& newEntry);
 24:    bool removeSorted(const ItemType& anEntry);
 25:    int getPosition(const ItemType& anEntry) const;
 26:    
 27:    // The inherited methods remove, clear, getEntry, isEmpty, and
 28:    // getLength have the same specifications as given in ListInterface.
 29:    
 30:    // The following methods must be overridden to disable their
 31:    // effect on a sorted list:
 32:    bool insert(int newPosition, const ItemType& newEntry) override;
 33:    void replace(int position, const ItemType& newEntry)
 34:         throw(PrecondViolatedExcept) override;
 35: }; // end SortedListIsA
 36: #include "SortedListIsA.cpp"
 37: #endif