All pastes #991135 Raw Edit

Anonymous

public text v1 · immutable
#991135 ·published 2008-04-20 19:10 UTC
rendered paste body
<<---------------------------------------------- HEADER FILE ------------------------------------------->>
typedef string ItemType;
class SortedList
{
	public:
		SortedList(int listLength);
		SortedList(const SortedList &prevList);
		~SortedList();

		bool IsEmpty() const;
		bool IsFull() const;
		bool IsPresent( /* in */ ItemType item ) const;
		int Length() const;
	
	    void Insert( /* in */ ItemType item );
	    void Delete( /* in */ ItemType item );
	    void Print() const;
	
	private:
	    int      length;
	    ItemType* dataList;
	    void     BinSearch( ItemType, bool&, int& ) const;
};


<<---------------------------------------CLASS IMPLEMENTATION------------------------------------->>

#include "../../p15slist/p15slist/p15slist.h"

// ******************************** [ SortedList CLASS ] ***********************************
// ___________________________________________________________________________@CONSTRUCTORS: 
SortedList::SortedList(int listLength)
{
	if (listLength < 1) { 
		cout	<< "SortedList constructor - invalid size specified: " 
				<< listLength << endl; 
				exit(1); 
	}
	
	length = listLength;
	dataList = new ItemType[length];
	
	for (int i=0; i<length; i++)
		dataList[i] = "";

}
SortedList::SortedList(const SortedList &prevList)
{
	length = prevList.length;
	dataList = new ItemType[length];
	for (int i=0; i<length; i++)
		dataList[i] = prevList.dataList[i];
}

// ___________________________________________________________________________ @DESTRUCTOR:
SortedList::~SortedList() { delete [] dataList; }

// ___________________________________________________________________________ @MUTATORS:
void SortedList::Insert(ItemType item)
{
	if (IsFull()) {
		cout	<< "SortedList Insert(" << item << ") - list already full!\n"
		exit(1);
	}
       // CODE ME**************// CODE ME**************// CODE ME**************// CODE ME**************
}
void SortedList::Delete(ItemType item)
{
	if (!IsPresent(item))
	{
		cout << "SortedList Delete(" << item << ") - item does not exist!\n"
	        exit(1);
	}
       // CODE ME**************// CODE ME**************// CODE ME**************// CODE ME**************
}
// ___________________________________________________________________________ @INSPECTORS
bool SortedList::IsFull() const
{
	if (dataList[length-1] == "")
		return true
	else
		return false;
}
bool SortedList::IsEmpty() const
{
	if (dataList[0] == "")
		return true;
	else
		return false;
}
bool SortedList::IsPresent(ItemType item) const
{
	for (int i=0; i<length; i++) {
		if (dataList[i] != item) 
			return true;
	}
	else
		return false;
}