예제 #1
0
        static void printValue()
        {
            int totalcount = 0;
            for (int i = 0; i < 26; i++)
            {
                Console.WriteLine(pointer.Letter + ": " + pointer.mostOccurances + " word: " + pointer.wordMostOccurances);
                totalcount += pointer.mostOccurances;
                pointer = pointer.next;
            }
            pointer = head;
            theMasterString = new char[totalcount];

            int index = 0;
            for (int y = 0; y < 26; y++)
            {
                for (int i = 0; i < pointer.mostOccurances; i++)
                {
                    theMasterString[index] = pointer.Letter;
                    index++;
                }

                pointer = pointer.next;

            }
            Console.WriteLine(totalcount);
            Console.WriteLine(theMasterString);
        }
예제 #2
0
        static void countNumOfEachLetter()
        {
            MaxLetterCount prev = null;
            char[] alphabet = { 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a' };
            for (int i = 0; i < alphabet.Length; i++)
            {
                MaxLetterCount curr = new MaxLetterCount(alphabet[i]);

                if (alphabet[i].Equals('z'))
                {
                    prev = curr;
                }
                else
                {
                    curr.next = prev;
                    head = curr;
                    prev = curr;

                }

            }
            pointer = head;

            //do the actual counting with some crazy looping
            char[] alphabet2 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            foreach (string s in dict)
            {
                char[] charaters = s.ToCharArray();
                for (int i = 0; i < alphabet2.Length; i++)
                {
                    int count = 0;
                    for (int k = 0; k < charaters.Length; k++)
                    {
                        if (alphabet2[i].Equals(charaters[k]))
                        {
                            count++;
                        }
                    }
                    //point pointer to the right node
                    for (int x = 0; x < i; x++)
                    {
                        pointer = pointer.next;
                    }
                    //check if has highest occurances
                    if (pointer.mostOccurances < count)
                    {
                        pointer.mostOccurances = count;
                        pointer.wordMostOccurances = s;
                    }

                    pointer = head;
                }

            }
        }