Example #1
0
        public static string RepeatedWords(string words)
        {
            if (words == null || words == "")
            {
                return(null);
            }

            HashTable myTable        = new HashTable(100);
            var       rx             = new Regex(@"\s+l,\s+", RegexOptions.Compiled);
            string    lowerCaseWords = words.ToLower();

            string[] allWords = rx.Split(lowerCaseWords);

            foreach (string word in allWords)
            {
                int            index   = HashTable.HashCode(word);
                HashTable.Node current = myTable.Buckets[index];

                if (myTable.Buckets[index] != null && current.Value == word)
                {
                    return(word);
                }

                myTable.AddHash(word, word);
            }

            return(null);
        }
Example #2
0
        public static List <int> TreeIntersection(BinarySearchTree <int> firstTree, BinarySearchTree <int> secondTree)
        {
            HashTable  myTable = new HashTable(10);
            List <int> result  = new List <int>();

            List <int> firstTreeValue  = firstTree.PreOrder(firstTree.Root).ToList();
            List <int> secondTreeValue = secondTree.PreOrder(secondTree.Root).ToList();

            foreach (int value in firstTreeValue)
            {
                string keyOne = value.ToString();
                myTable.AddHash(keyOne, null);
            }

            foreach (int value in secondTreeValue)
            {
                string         keyTwo       = value.ToString();
                int            currentIndex = HashTable.HashCode(keyTwo);
                HashTable.Node current      = myTable.Buckets[currentIndex];

                while (current != null)
                {
                    if (current.Value == value.ToString())
                    {
                        int match = value;
                        result.Add(match);
                        break;
                    }
                    else
                    {
                        current = current.Next;
                    }
                }
            }
            return(result);
        }