CpSc 212 Assignment 2: Implementing an Efficient Range-Set Storage, Assignments of Algorithms and Programming

An assignment for computer science students in course cpsc 212 during the summeri’09 semester. The assignment requires students to create a class named rangeset that maintains a set of integers as a linked list of ranges, with methods to add, delete, merge, and display ranges. Students must ensure the linked list is stored in increasing order and in minimal form.

Typology: Assignments

Pre 2010

Uploaded on 07/28/2009

koofers-user-ird
koofers-user-ird 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CpSc 212 - SummerI’09 - Goddard
Assignment 2
Due 8pm Sunday 7 June
Efficient Range-Set Storage. You are to produce a class RangeSet that main-
tains a set of integers, including methods to update and display the set in terms of ranges.
For example, given the two ranges 17..21 and 22..25, the program will automatically merge
them to give 17..25. Input ranges may be given in any order. If there is only one number
in a range, only one number should be displayed. Example: given 3, 5, 1, 17..19, 4 the
output would be 1, 3..5, 17..19. The class must be able to handle an arbitrary number of
input ranges and there is no constraint on the ranges the user can enter.
Your class must store the range set as a linked list of the struct RNode.
struct RNode {
int start, end;
RNode* next;
}
Each RNode represents a range of integers. The linked list MUST be stored in increasing
order and in minimal form; that is, no two nodes’ ranges overlap. So, no matter what
sequence of operations gives rise to it, the set {1,3,4,5,17,18,19}must be stored as 3
nodes representing ranges 1..1,3..5 and 17..19 in that order.
Instructions
Produce a class which maintains a set of integers with methods to update and display
the set in terms of ranges. It should have the following methods:
void addRange(int rangeStart,int rangeEnd);
// adds all integers from RANGESTART to RANGEEND inclusive to the set
RangeSet union(const RangeSet &alpha, const RangeSet &beta);
// creates a new RangeSet that is the union of two supplied RangeSets
bool isInSet(int element) const;
// returns whether the value ELEMENT is in the set or not
void deleteRange(int rangeStart, int rangeEnd);
// deletes all integers from RANGESTART to RANGEEND inclusive
void deleteAllElements() const;
// makes the set empty
void dump(bool inIncreasingOrder) const
// prints out the set in a series of ranges with order specified
as well as a default constructor, a destructor, and an equality tester (==).
pf2

Partial preview of the text

Download CpSc 212 Assignment 2: Implementing an Efficient Range-Set Storage and more Assignments Algorithms and Programming in PDF only on Docsity!

CpSc 212 - SummerI’09 - Goddard Assignment 2 Due 8pm Sunday 7 June Efficient Range-Set Storage. You are to produce a class RangeSet that main- tains a set of integers, including methods to update and display the set in terms of ranges. For example, given the two ranges 17..21 and 22..25, the program will automatically merge them to give 17..25. Input ranges may be given in any order. If there is only one number in a range, only one number should be displayed. Example: given 3, 5, 1, 17..19, 4 the output would be 1, 3..5, 17..19. The class must be able to handle an arbitrary number of input ranges and there is no constraint on the ranges the user can enter. Your class must store the range set as a linked list of the struct RNode.

struct RNode { int start, end; RNode* next; }

Each RNode represents a range of integers. The linked list MUST be stored in increasing order and in minimal form; that is, no two nodes’ ranges overlap. So, no matter what sequence of operations gives rise to it, the set { 1 , 3 , 4 , 5 , 17 , 18 , 19 } must be stored as 3 nodes representing ranges 1..1, 3..5 and 17..19 in that order.

Instructions

Produce a class which maintains a set of integers with methods to update and display the set in terms of ranges. It should have the following methods:

void addRange(int rangeStart,int rangeEnd); // adds all integers from RANGESTART to RANGEEND inclusive to the set

RangeSet union(const RangeSet &alpha, const RangeSet &beta); // creates a new RangeSet that is the union of two supplied RangeSets

bool isInSet(int element) const; // returns whether the value ELEMENT is in the set or not

void deleteRange(int rangeStart, int rangeEnd); // deletes all integers from RANGESTART to RANGEEND inclusive

void deleteAllElements() const; // makes the set empty

void dump(bool inIncreasingOrder) const // prints out the set in a series of ranges with order specified

as well as a default constructor, a destructor, and an equality tester (==).

HINT: addRange is challenging! Start by writing it on the assumption that the user will NEVER input ranges that overlap or merge. Write some of the other methods. Test and debug under the user assumption. Write all of the other methods. Test and debug under the user assumption. Then, and only then, go back and try to make it work fully. You may NOT use any data structure from the C++ Standard Template Library or other such Data Structures package. You should write and submit a test program called TestRange.cpp that vigorously tests your class.

Submission

Submit your source code using handin.212.301 2 YOUR FILES

You are to work independently, but can ask questions from the lecturer and lab instruc- tor(s). Late submissions will be significantly penalized.