Source of Listing12-3.h


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

  4: /** ADT sorted list using the ADT list.
  5:  @file SortedListHasA.h */
  6: #ifndef SORTED_LIST_HAS_A_
  7: #define SORTED_LIST_HAS_A_
  8: #include <memory>
  9: #include "SortedListInterface.h"
 10: #include "ListInterface.h"
 11: #include "Node.h"
 12: #include "PrecondViolatedExcept.h"

 14: template<class ItemType>
 15: class SortedListHasA : public SortedListInterface<ItemType>
 16: {
 17: private:
 18:    std::unique_ptr<ListInterface<ItemType>> listPtr;
 19:    
 20: public:
 21:    SortedListHasA();
 22:    SortedListHasA(const SortedListHasA<ItemType>& sList);
 23:    virtual ~SortedListHasA();
 24:    
 25:    bool insertSorted(const ItemType& newEntry);
 26:    bool removeSorted(const ItemType& anEntry);
 27:    int getPosition(const ItemType& newEntry) const;
 28:    
 29:    // The following methods have the same specifications
 30:    // as given in ListInterface in Chapter 8:
 31:    bool isEmpty() const;
 32:    int getLength() const;
 33:    bool remove(int position);
 34:    void clear();
 35:    ItemType getEntry(int position) const throw(PrecondViolatedExcept);
 36: }; // end SortedListHasA
 37: #include "SortedListHasA.cpp"
 38: #endif