public static TrieNode fileInsert() { ReadFileData(); TrieNode tree = new TrieNode('\0'); for (int i = 0; i < Dictionary.W.Length(); i++) { PrefixTree.InsertWordInTrie(tree, Dictionary.W.Get(i), Dictionary.j, Dictionary.k); Dictionary.j = Dictionary.j + 4; Dictionary.k++; } return(tree); }
public void InsertWord(TrieNode tree) { TextWriter tsw = new StreamWriter(@"file.txt", true); string[] SynonymToBeInserted = new string[4]; string[] AntonymToBeInserted = new string[4]; if (textBox2.Text == "") { MessageBox.Show("Please enter the WORD properly ", "Warning", MessageBoxButtons.OK); return; } else if (textBox3.Text == "") { MessageBox.Show("Please enter MEANING of the Word properly ", "Warning", MessageBoxButtons.OK); return; } else if (textBox4.Text == "") { MessageBox.Show("Please enter SENTENCE of the Word as an example", "Warning", MessageBoxButtons.OK); return; } string w = textBox2.Text.ToString(); Dictionary.W.Insert(w); string t = textBox3.Text.ToString(); Dictionary.ListOfTranslations.Insert(t); string ex = textBox4.Text.ToString(); Dictionary.ListOfExamples.Insert(ex); string synonym = textBox5.Text.ToString(); SynonymToBeInserted = synonym.Split(','); if (SynonymToBeInserted.Length != 4) { MessageBox.Show("You can enter maximum FOUR Synonyms, Please follow the given pattern:\n\n <Synonym1>,<Synonym2>,<Synonym3>,<Synonym4>\n\nIf you want to insert less than four than write <space> in place of Synonyms ", "Warning", MessageBoxButtons.OK); return; } else { for (int i = 0; i < SynonymToBeInserted.Length; i++) { Dictionary.ListOfSynonyms.Insert(SynonymToBeInserted[i]); } } string antonym = textBox6.Text.ToString(); AntonymToBeInserted = antonym.Split(','); if (AntonymToBeInserted.Length != 4) { MessageBox.Show("You can enter maximum FOUR Antonyms, Please follow the given pattern:\n\n <Antonym1>,<Antonym2>,<Antonym3>,<Antonym4>\n\nIf you want to insert less than four than write <space> in place of Antonym ", "Warning", MessageBoxButtons.OK); return; } else { for (int i = 0; i < AntonymToBeInserted.Length; i++) { Dictionary.ListOfAntonyms.Insert(AntonymToBeInserted[i]); } } PrefixTree.InsertWordInTrie(tree, w, Dictionary.j, Dictionary.k); Dictionary.j = Dictionary.j + 4; Dictionary.k++; tsw.WriteLine(); tsw.WriteLine("{0}", w); tsw.WriteLine("{0}", t); tsw.WriteLine("{0}", ex); tsw.WriteLine("{0},{1},{2},{3}", SynonymToBeInserted[0], SynonymToBeInserted[1], SynonymToBeInserted[2], SynonymToBeInserted[3]); tsw.Write("{0},{1},{2},{3}", AntonymToBeInserted[0], AntonymToBeInserted[1], AntonymToBeInserted[2], AntonymToBeInserted[3]); tsw.Close(); }