Exemplo n.º 1
0
        //Return the union of this set with the one pass as an argument. O(n*m)
        public SetInterface Union(SetInterface set)
        {
            ArraySet res = new ArraySet(set.Enumerate());

            for (int i = 0; i < _size; i++)
            {
                if (!set.Contains(_items[i]))
                {
                    res.Add(_items[i]);
                }
            }
            return(res);
        }
Exemplo n.º 2
0
        //Return the union of this set with the one pass as an argument. O(n*m)
        public SetInterface Union(SetInterface set)
        {
            LinkedSet        res  = new LinkedSet(set.Enumerate());
            SinglyLinkedNode curr = _head;

            while (curr != null)
            {
                if (!set.Contains(curr.Item))
                {
                    res.Add(curr.Item);
                }
                curr = curr.Next;
            }
            return(res);
        }
Exemplo n.º 3
0
 //Determine if this set contains as a subset the set pass as an argument. O(n*m)
 public bool Subset(SetInterface set)
 {
     Object[] setObj = set.Enumerate();
     if (setObj.Length > _size)
     {
         return(false);
     }
     for (int i = 0; i < setObj.Length; i++)
     {
         if (!Contains(setObj[i]))
         {
             return(false);
         }
     }
     return(true);
 }