Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            //if (obj == null) return false;
            //if (obj == this) return true;

            //if (!(obj is Student))
            //	return false;

            //Student student = obj as Student;

            //return this._id == student._id;


            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            if (!(obj is CharacterFrequency))
            {
                return(false);
            }

            CharacterFrequency ourCharObj = (CharacterFrequency)obj;

            return(this.Character == ourCharObj.Character);

            //bool equal = false;
            //CharacterFrequency frequency = new CharacterFrequency((char)aChar);
            //frequency = (CharacterFrequency) aChar;
            //if (this.Character == frequency.Character) equal = true;
            //return equal;
        }
Exemplo n.º 2
0
        private static void HandleFile(char[] chars)
        {
            LinkedList <CharacterFrequency> frequencyList = new LinkedList <CharacterFrequency>();

            foreach (char aCharacter in chars)
            {
                CharacterFrequency cf = new CharacterFrequency(aCharacter);

                if (frequencyList.Contains(new CharacterFrequency(aCharacter)))
                {
                    cf.IncrementFrequency(); // ugh, this doesn't work.
                }
                else
                {
                    frequencyList.AddLast(cf);
                }
            }

            //LinkedList<CharacterFrequency> frequencyList = new LinkedList<CharacterFrequency>();

            //foreach (char aCharacter in chars)
            //{
            //    CharacterFrequency cf = new CharacterFrequency(aCharacter);
            //    frequencyList.AddLast(cf);
            //    foreach (CharacterFrequency freq in frequencyList)
            //    {
            //        if (frequencyList.Contains(new CharacterFrequency(aCharacter)))
            //        {
            //            cf.IncrementFrequency(); // ugh, this doesn't work.
            //        }
            //    }
            //}

            foreach (CharacterFrequency freq in frequencyList)
            {
                Console.WriteLine(freq.ToString()); // This outputs everything but the counts, which are 0.
            }
        }