<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>Lowyat.NET: Latest topics by midnight_blue</title>
        <description></description>
        <link>http://forum.lowyat.net/</link>
        <lastBuildDate>Sun, 01 Nov 2026 03:33:54 +0800</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>Need help with Binary Search Tree</title>
            <link>http://forum.lowyat.net/topic/360287</link>
            <description>I&amp;#39;m doing an assignment on a basic spell checker, and I&amp;#39;m stuck at the part where I&amp;#39;m required to have a binary search tree to store the words (a small dictionary). &lt;br /&gt;&lt;br /&gt;[Problem 1]&lt;br /&gt;To my understanding, the insert method will arrange them alphabetically. But I couldn&amp;#39;t figure out how to find the words lying next to a target word. &lt;br /&gt;&lt;br /&gt;If a word is not found in the dictionary, it&amp;#39;s supposed to return the words exactly next to it. So I have a method findImmediate(String wrongWord) that returns a Queue. Say if wrongWord is &amp;quot;icee&amp;quot;, the Queue will contain the words &amp;quot;ice&amp;quot; and &amp;quot;ices&amp;quot;.&lt;br /&gt;&lt;br /&gt;How should I manipulate the binary search tree to do that?&lt;br /&gt;&lt;br /&gt;[Problem 2]&lt;br /&gt;Another part is to write the words in the binary search tree to a text file. Is it correct for me to do this? :&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;public void toFile&amp;#40;&amp;#41; {&lt;br /&gt; &amp;nbsp;if &amp;#40;&amp;#33;bst.isEmpty&amp;#40;&amp;#41;&amp;#41; {&lt;br /&gt; &amp;nbsp; &amp;nbsp; bst.depthFirstTraversal&amp;#40; new AbstractPrePostVisitor&amp;#40;&amp;#41; {&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void inVisit&amp;#40;Object obj&amp;#41; {&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BufferedWriter bw = new BufferedWriter&amp;#40;new FileWriter&amp;#40;&amp;#34;newWords.txt&amp;#34;&amp;#41;&amp;#41;;&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;bw.write&amp;#40;&amp;#40;&amp;#40;Str&amp;#41;obj&amp;#41;.stringValue&amp;#40;&amp;#41;&amp;#41;;&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch &amp;#40;IOException ioe&amp;#41; {&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println&amp;#40;&amp;#34;Error writing to newWords.txt..&amp;#34;&amp;#41;;&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt; &amp;nbsp; &amp;nbsp; } &amp;#41;;&lt;br /&gt; &amp;nbsp;}&lt;br /&gt;}&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Doesn&amp;#39;t seem to work; the text file is empty, even though the System.out.println() works fine in the inVisit().  &lt;!--emo&amp;:stars:--&gt;&lt;img src='http://static.lowyat.net/style_emoticons/default/rclxub.gif' border='0' style='vertical-align:middle' alt='rclxub.gif' /&gt;&lt;!--endemo--&gt; &lt;br /&gt;&lt;br /&gt;I&amp;#39;d really appreciate some guide, thanks&amp;#33;  &lt;!--emo&amp;:help:--&gt;&lt;img src='http://static.lowyat.net/style_emoticons/default/icon_question.gif' border='0' style='vertical-align:middle' alt='icon_question.gif' /&gt;&lt;!--endemo--&gt;</description>
            <author>midnight_blue</author>
            <category>Codemasters</category>
            <pubDate>Mon, 30 Oct 2006 21:24:36 +0800</pubDate>
        </item>
    </channel>
</rss>
