CSC 240

Exercise 2

Extend the UnsortedType class with the following function and signature:

SplitLists(UnsortedType list, ItemType item, UnsortedType& list1, UnsortedType& list2)

The SplitLists function will behave according to the following specifications:

Definition: divides list into two lists according to the value of item.

Preconditions: list has been initialized and is not empty. list1 contains all the items of list whose values are less than or equal to the value of item.

Postconditions: list2 contains all of the items of list whose values are greater than the value of item.

Complete the following implementations of the SplitLists function:

1) Implement SplitLists as an array-based member function of UnsortedType.

2) Implement SplitLists as a linked member function of UnsortedType.

Test each of the implementations in a driver using the following set of integers:

{ 5, -12, 34, 34, 5, 45, 8, -6, 15, 40, 20, 2, 1, 12 }

Use the following version of the ItemType class provided by the author:

class ItemType

{

public:

ItemType();

RelationType ComparedTo(ItemType) const;

void Print(std::ostream&) const;

void Initialize(int number);

private:

int value;

};

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now