Example #1
0
        // Make sure the 2 lists have equal value
        // (*** does not check for unique items.  Use IsUnique() *** )
        public bool AreEqual(LinkedListHandler otherItem)
        {
            if (this.Length != otherItem.Length)
            {
                return(false);
            }

            // Starting from head of the list to the last item,
            // check whether both items' value are equal.
            var item1 = this.Item;
            var item2 = otherItem.Item;
            int count = 0;

            while (item1 != null && count++ < this.Length)
            {
                if (!item1.Equals(item2))
                {
                    return(false);
                }

                item1 = item1.Next;
                item2 = item2.Next;
            }

            return(true); // all equal
        }
Example #2
0
        // compare 2 list items to ensure every item is unique
        // (there are no shared items between the 2 lists)
        public bool IsUnique(LinkedListHandler otherItem)
        {
            if (object.ReferenceEquals(this, otherItem))
            {
                return(false);
            }

            foreach (var i in this.ItemHash)
            {
                if (otherItem.ItemHash.Contains(i))
                {
                    return(false);
                }
            }

            return(true); // no duplicates => unique
        }