public class Set_Array extends Object implements ISet
Modifier and Type | Field and Description |
---|---|
protected int |
current |
protected boolean[] |
elements |
Constructor and Description |
---|
Set_Array(int n)
Creates a set represented by an array of booleans
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int element)
Add element to the set
Does not guaranty there is no duplications
|
void |
clear()
Remove all elements from the set
|
boolean |
contain(int element)
Test the existence of element in the set
|
int |
getFirstElement() |
int |
getMaxSize()
Gets the maximum size of the set, or -1 if it is unbounded.
|
int |
getNextElement()
enables to iterate over the set
should be used as follow :
for(int i=getFirstElement(); i>=0; i = getNextElement()){
...
}
The use of getFirstElement() is necessary to ensure a complete iteration
WARNING cannot encapsulate two for loops (copy the set for that)
|
SetType |
getSetType() |
int |
getSize() |
boolean |
isEmpty() |
boolean |
remove(int element)
Remove the first occurence of element from the set
|
int[] |
toArray()
Copies the set in an array if integers
|
public Set_Array(int n)
n
- maximal size of the setpublic boolean add(int element)
ISet
public boolean remove(int element)
ISet
public boolean contain(int element)
ISet
public boolean isEmpty()
public int getSize()
public void clear()
ISet
public int getFirstElement()
getFirstElement
in interface ISet
public int getNextElement()
ISet
getNextElement
in interface ISet
public SetType getSetType()
getSetType
in interface ISet
public int[] toArray()
ISet
public int getMaxSize()
ISet
getMaxSize
in interface ISet
Copyright © 2015. All rights reserved.