Public paste
SET ADT
By: Blake | Date: Sep 16 2010 23:49 | Format: None | Expires: never | Size: 1.27 KB | Hits: 820

  1. public class Set
  2. {
  3.    public Set()
  4.    {
  5.      // creates a set with capacity of 100 to empty states
  6.    }
  7.    public void add(Object object)
  8.    {
  9.       // need to know the current location in the array.
  10.  
  11.       myArray[currentpos +1] = this.object;
  12.    }
  13.    public boolean contains(Object object)
  14.    {
  15.      for(int i =0; i < myArray.size(); i++)
  16.      {
  17.         if(this.object.equals(myArray[i]))
  18.         {
  19.           isthere = true;
  20.         }
  21.         else
  22.         {
  23.           isthere = false;
  24.         }
  25.      }
  26.      return(isthere);
  27.    }
  28.    public Object getFirst()
  29.    {
  30.      if(myArray[i] != null)
  31.      {
  32.        return(myArray[0]);
  33.      }
  34.      else
  35.      {
  36.        System.out.println("Doesn't exist");
  37.      }
  38.    }
  39.    public Object getNext()
  40.    {
  41.      // to do this we need to keep track of the current location in the array.
  42.      return(myArray[currentLocation])
  43.      currentlocation++;
  44.    }
  45.    public boolean remove(Object object)
  46.    {
  47.       for(int i =0; i< myArray.size(); i++)
  48.       {
  49.          if(myArray[i].equals(this.object))
  50.          {
  51.              myArray[i] = null;
  52.              booleanisremoved = true;
  53.          }
  54.       }
  55.       return(booleanisremoved);
  56.      
  57.    }
  58.    public int size()
  59.    {
  60.       return(myArray.size());
  61.    }
  62.  
  63. }// done