Untitled

 avatar
unknown
plain_text
4 years ago
1.7 kB
9
Indexable
 public static async Task Async(string fileName)
        {
            const int MAX_FILE_LINES = 50000;
            string[] AllLines = new string[MAX_FILE_LINES];

            AVLTree<string> tree = new AVLTree<string>();

            AllLines = File.ReadAllLines(fileName);

            foreach(string line in AllLines)
            {
                string[] words = line.Split(' ', ',', '.', '?', ';', ':', '!');
                foreach (string word in words)
                    if (word != "")
                        //  Console.WriteLine(word.ToLower());
                        tree.InsertItem(word.ToLower());
            }
            StreamWriter sw = new StreamWriter(fileName);
            sw.WriteLine("Number of words {0}", tree.Count());

            int n = tree.Count();
            string a = Convert.ToString(n);

         //   await File.WriteAllLinesAsync("textfile.txt", a);
          // sw.WriteLine("Number of times each word appears {0}",  );


        }
        public static void CountStringOccurrences(string fileName, string word)
        {
            int count = 0;
            int i = 0;
            while ((i = fileName.IndexOf(word, i)) != -1)
            {
                i += word.Length;
                count++;
            }
            Console.WriteLine("Number of times each words was repeated {0}", count, word);

        }





Enhance your task A application to store both the word and the number of occurrences of the word in a supplied text file.  Your application must also make use of an AVLTree and should display all the unique words in the supplied file as well as the number of times each word occurred
Editor is loading...