// File:  IntegerSet.cpp
//
// By: Cedric F. Lam
// UCLA - EE
// 3-13-1998
//

#include <iostream.h>
#include "IntegerSet.h"

// Constructor
IntegerSet::IntegerSet(int i1, int i2, int i3, int i4, int i5)
{
	for(int i=0; i<=100; i++)
		a[i] =0;

	if( i1>=0 && i1 <= 100)
		a[i1] = 1;
	if( i2>=0 && i2 <= 100)
		a[i2] = 1;
	if( i3>=0 && i3 <= 100)
		a[i3] = 1;
	if( i4>=0 && i4 <= 100)
		a[i4] = 1;
	if( i5>=0 && i5 <= 100)
		a[i5] = 1;
}

// Insert element m to the set if  0 <= m <= 100.
IntegerSet& IntegerSet::insertElement(int m)
{
	if(m>=0 && m<=100)
		a[m] = 1;
	return *this;
}

// Delete element m from the set where 0 <= m <= 100.
IntegerSet& IntegerSet::deleteElement(int m)
{
	if(m>=0 && m<=100)
		a[m] = 0;
	return *this;
}

// Return the union of two IntegerSets.
IntegerSet IntegerSet::unionOfIntegerSets(const IntegerSet &T) const
{
	IntegerSet unionset;

	for(int i=0; i<=100; i++)
		unionset.a[i] = a[i] || T.a[i];

	return unionset;
}

// Return the intersection of two IntegerSets.
IntegerSet IntegerSet::intersectionOfIntegerSets(const IntegerSet &T) const
{
	IntegerSet intersection;

	for(int i=0; i<=100; i++)
		intersection.a[i] = a[i] && T.a[i];

	return intersection;
}

// Return 1 if the two sets are equal, 0 otherwise.
int IntegerSet::isEqualTo(const IntegerSet &T) const
{
	for(int i=0; i<=100; i++)
		if(a[i] != T.a[i])
			return 0;
	return 1;
}

// Return 1 if the set is empty, 0 otherwise
int IntegerSet::isEmpty() const
{
	for(int i=0; i<=100; i++)
		if(a[i]) 	// non-empty element found
			return 0;
	return 1;
}

// Display the IntegerSet, empty set is represented by ---
void IntegerSet::setPrint() const
{
	if(isEmpty())
		cout << "---" << endl;
	else{
		cout << "< ";
		for(int i=0; i<=100; i++)
			if(a[i])
				cout << i << " ";
		cout << ">" << endl;
	}
}


