Пример #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);
        }
Пример #2
0
        //Return the intersection between this set and the one pass as an argument. O(n*m)
        public SetInterface Intersection(SetInterface set)
        {
            ArraySet res = new ArraySet();

            for (int i = 0; i < _size; i++)
            {
                if (set.Contains(_items[i]))
                {
                    res.Add(_items[i]);
                }
            }
            return(res);
        }
Пример #3
0
        //Return the intersection between this set and the one pass as an argument O(n*m)
        public SetInterface Intersection(SetInterface set)
        {
            LinkedSet        res  = new LinkedSet();
            SinglyLinkedNode curr = _head;

            while (curr != null)
            {
                if (set.Contains(curr.Item))
                {
                    res.Add(curr.Item);
                }
                curr = curr.Next;
            }
            return(res);
        }
Пример #4
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);
 }