Example #1
0
        public void Contains()
        {
            Multiset <string> multiset = new Multiset <string>();

            multiset.Add("a");

            Assert.IsTrue(multiset.Contains("a"));

            multiset.Add("a");

            Assert.IsTrue(multiset.Contains("a"));

            multiset.Remove("a");
            multiset.Remove("a");

            Assert.IsFalse(multiset.Contains("a"));
        }
Example #2
0
        public void Contains()
        {
            Multiset<string> multiset = new Multiset<string>();

            multiset.Add("a");

            Assert.IsTrue(multiset.Contains("a"));
            
            multiset.Add("a");
            
            Assert.IsTrue(multiset.Contains("a"));
            
            multiset.Remove("a");
            multiset.Remove("a");
            
            Assert.IsFalse(multiset.Contains("a"));
        }
Example #3
0
        private static void Multiset(ListNode<int> head)
        {
            Multiset<int> multiset = new Multiset<int>();
            ListNode<int> previous = null;

            while(head != null)
            {
                if (multiset.Contains(head.Value))
                    previous.Next = head.Next;
                else
                {
                    previous = head;
                    multiset.Add(head.Value);
                }

                head = head.Next;
            }
        }
Example #4
0
        private static void Multiset(ListNode <int> head)
        {
            Multiset <int> multiset = new Multiset <int>();
            ListNode <int> previous = null;

            while (head != null)
            {
                if (multiset.Contains(head.Value))
                {
                    previous.Next = head.Next;
                }
                else
                {
                    previous = head;
                    multiset.Add(head.Value);
                }

                head = head.Next;
            }
        }