Ejemplo n.º 1
0
        public void Execute()
        {
            BinarySearchST <string, int> st = new BinarySearchST <string, int>(a.Length);

            Array.Sort(a); // we sort because we use binary search inside

            //adding
            for (int i = 0; i < a.Length; i++)
            {
                // to Key we write Word, to Value we write Frequency
                if (!st.contains(a[i]))
                {
                    st.put(a[i], 1);
                }
                else
                {
                    st.put(a[i], st.get(a[i]) + 1);
                }
            }
            //st.ConsoleDisplay();
            // search max frequent word
            string maxFrequentWord = " ";

            st.put(maxFrequentWord, 0);

            foreach (var val in st)
            {
                if ((val != null) && (st.get(val) > st.get(maxFrequentWord)))
                {
                    maxFrequentWord = val;
                }
            }
            Console.WriteLine("maxFrequentWord=" + maxFrequentWord + " maxFrequency " + st.get(maxFrequentWord));
            st.ConsoleDisplay();
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            BinarySearchST <string, int> st = new BinarySearchST <string, int>();

            Array.Sort(a); // we sort because we use binary search inside

            //adding
            for (int i = 0; i < a.Length; i++)
            {
                st.put(a[i], i);
            }
            if (st.contains("X"))
            {
                Console.WriteLine("Yes! Contains X");
            }
            st.ConsoleDisplay();
            // st.delete("L");
            // Console.WriteLine();
            // st.ConsoleDisplay();
        }