- public class Set
- {
- public Set()
- {
- // creates a set with capacity of 100 to empty states
- }
- public void add(Object object)
- {
- // need to know the current location in the array.
- myArray[currentpos +1] = this.object;
- }
- public boolean contains(Object object)
- {
- for(int i =0; i < myArray.size(); i++)
- {
- if(this.object.equals(myArray[i]))
- {
- isthere = true;
- }
- else
- {
- isthere = false;
- }
- }
- return(isthere);
- }
- public Object getFirst()
- {
- if(myArray[i] != null)
- {
- return(myArray[0]);
- }
- else
- {
- System.out.println("Doesn't exist");
- }
- }
- public Object getNext()
- {
- // to do this we need to keep track of the current location in the array.
- return(myArray[currentLocation])
- currentlocation++;
- }
- public boolean remove(Object object)
- {
- for(int i =0; i< myArray.size(); i++)
- {
- if(myArray[i].equals(this.object))
- {
- myArray[i] = null;
- booleanisremoved = true;
- }
- }
- return(booleanisremoved);
- }
- public int size()
- {
- return(myArray.size());
- }
- }// done
SET ADT
By: Blake | Date: Sep 16 2010 23:49 | Format: None | Expires: never | Size: 1.27 KB | Hits: 869
Latest pastes
16 hours ago
2 days ago
3 days ago
6 days ago
7 days ago