Friday, 27 September 2013

ADT Set (array set) in java, removing items and intersection and union of sets

ADT Set (array set) in java, removing items and intersection and union of
sets

Note: This is for an assignment
I can't figure out how to write the intersecting & union methods-- this is
one of my first CS classes that I've taken and I'm having a difficult
time. Can anyone offer any assistance?
public class ArraySet<T> implements SetInterface<T>
{
private final T[] set;
private static final int defaultCapacity = 10;
private int count;
public ArraySet(int aCapacity)
{
count = 0;
T[] tempSet = (T[]) new Object [aCapacity];
set = tempSet;
}
public ArraySet()
{
this (defaultCapacity);
}
public void insert(T anElement)
{
if (set.equals(anElement))
{
return;
} else {
set[count] = anElement;
count ++;
}
}
public T remove()
{
T result = remove (count - 1);
return result;
}
public int getCurrentSize()
{
return count;
}
public boolean isEmpty()
{
return count == 0;
}
public String toString()
{
String temp = new String ();
}
public boolean in(T anElement)
{
boolean result = true;
if (a.equals(anElement))
{
result = false;
} else {
}
public SetInterface<T> intersect(SetInterface<T> rhsSet)
{
/**
* Perform union operation between this set and the rhsSet.
* @param rhsSet the set to be unioned with.
* @return a new set which is the result of this set unions with
* rhsSet.
*/
}
public SetInterface<T> union(SetInterface<T> rhsSet)
{
/**
* Perform diff operation between this set and the rhsSet.
* @param rhsSet the set to be diffed with.
* @return a new set which is the result of this set diffs with
* rhsSet.
*/
}
public SetInterface<T> diff(SetInterface<T> rhsSet)
{
/**
* See whether this set is a subset of rhsSet.
* @param rhsSet an input set.
* @return true if this set is a subset of rhsSet, false otherwise.
*/
}
public boolean subsetOf(SetInterface<T> rhsSet)
{
/**
* See whether this set is equal to the set otherObject.
* Note that this method overrides the method equals of the class
* Object.
* @param otherObject an input set.
* @return true if this set is equal the set otherObject.
*/
}
public boolean equals(Object otherObject)
{
/**
* Creates an array of all elements that are in this set.
* @return a newly allocated array of all the entries in this set.
*/
}
public T[] toArray()
{
T[] result = (T[]) new Object [count];
for (int index = 0; index < count; index++)
{
result [index] = set [index];
}
return result;
}
}

No comments:

Post a Comment