Exemple #1
0
 public NodeF(string word, NodeF left, NodeF right) // конструктор
 {
     Count = 1;
     Word  = word;
     Right = right;
     Left  = left;
 }
Exemple #2
0
        private NodeF _generateFreqTree(Queue <string> words)
        {
            while (words.Count != 0)                       //пока не пустая очередь
            {
                var current = Root;                        //начиная с корня
                var word    = words.Dequeue();             //запоминаем  слово
                var node    = new NodeF(word, null, null); //создаем node


                while (current != null && word.CompareTo(current.Word) != 0) //пока текущий не null и слово в ноде не равно тому, которое мы запомнили
                {
                    if (word.CompareTo(current.Word) == 1)                   // если запомненное слово больше
                    {
                        if (current.Right != null)
                        {
                            current = current.Right; //move to right
                        }
                        else
                        {
                            current.Right = node; //create node in right branch
                            break;
                        }
                        continue;
                    }


                    if (word.CompareTo(current.Word) == -1)
                    {
                        if (current.Left != null)
                        {
                            current = current.Left;
                        }
                        else
                        {
                            current.Left = node;
                            break;
                        }

                        continue;
                    }
                }
                if (word.CompareTo(current?.Word) == 0) //check if words are equal
                {
                    current.Count++;
                }

                if (current == null)
                {
                    if (Root == null)
                    {
                        Root = node;
                    }
                    current = node;
                }
            }

            return(Root);
        }
Exemple #3
0
 void ConvertTreeToDGVR(DataGridView dataGridView, NodeF node, ref int i)// i - index
 {
     if (node == null)
     {
         return;
     }
     dataGridView.Rows.Add();
     dataGridView[0, i].Value = node.Word;
     dataGridView[1, i].Value = Convert.ToString((double)node.Count / (double)Count);
     i++;
     ConvertTreeToDGVR(dataGridView, node.Left, ref i);
     ConvertTreeToDGVR(dataGridView, node.Right, ref i);
 }
Exemple #4
0
 public Frequency(List <string> words)
 {
     Root  = Generate(words);
     Count = words.Count;
 }