コード例 #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);
        }