Results 1 to 2 of 2
  1. #1
    allergy01 is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default Need with my assignment ...

    Hey guys,
    ok, I have the following psudoecode to search a binary search tree for a word:

    to find the correct position.
    * we would need to search the tree
    * assuming it's a binary search tree
    * we compare the word to the top most node
    * if it's higher or lower determines whether we look to the right or left of the tree
    * we for loop through the tree (iteratively or recursively, assignment requires both) until we find the word or have searched all nodes.
    * if we find the word we insert the line position into the corresponding nodes list
    * with the list insertion, I dont think it matters how we do that, because it does not matter if the line and position values are at the start or end of the list, assuming many values, as loingas they can be associated with the correct node is all that matters.
    * If we dont find the word then we must seacrh the tree for the correct position to insert it
    * this we would do by searching for the word, this should lead to a null link, we can then replace that link to anode containing the word.
    * or by setting parent to null, set current to the bst's root
    * then looping through:
    - if current is null, replace null link which curent had with newly created leaf node with word
    - if word is equal to current then terminate // word exists
    - if word is less than current, set parent to current and set current to currents left child
    - if word is greater than current, set parent to current and set current to currents right child
    - then need to insert line position for this node in the List

    Heres the code that I have to apply it to,
    but I'm unsure of what to do next, or how to implement it,
    any help at all would be much apprecited,


    Java Code:
    class Tree091 /*(i.e., WordTree)*/
    { private char[] word=null;
      private List091 list=null;
      private Tree091 precursor=null; /*(i.e., leftSubTree)*/
      private Tree091 successor=null; /*(i.e., rightSubTree)*/
      public Tree091(char[] word,
                     List091 list,
                     Tree091 precursor, /*(i.e., lexicographically < word)*/
                     Tree091 successor) /*(i.e., lexicographically > word)*/
      { if (word==null) return;
        if (word.length<1) return;
        if (list==null) return;
      public void add(char[] word,
                      int line,
                      int position,
                      boolean iterative)
      { if (word==null) return;
        if (word.length<1) return;
        if (line<0) return;
        if (position<0) return;
        if (iterative)
      private void addIterative(char[] word,
                                int line,
                                int position)
        /* students to complete */
      private void addRecursive(char[] word,
                                int line,
                                int position)
         /* students to complete */
      private int compare(char[] array1,
                          char[] array2)
      { if (array1==null) return -2;
        if (array2==null) return -2;
        int length1=array1.length;
        if (length1==0) return -2;
        int length2=array2.length;
        if (length2==0) return -2;
        int minLength=length1<length2?length1:length2;
        for (int i=0; i<minLength; i++)
        { if (array1[i]<array2[i]) return -1;
          if (array1[i]>array2[i]) return 1;
        return length1==length2 ? 0 : length1<length2 ? -1 : 1;
      public boolean contained(char[] word)
      { int compare=compare(this.word,word);
        if (compare==1&&this.precursor!=null)
          return this.precursor.contained(word);
        if (compare==0) return true;
        if (compare==-1&&this.successor!=null)
          return this.successor.contained(word);
        return false;
      public int listNodeCount(boolean iterative)
        /* students to complete */
      public int maximumWordLength(int currentLength)
        /* students to complete */
      public String toString()
      { String string="";
        if (this.precursor!=null) string+=this.precursor;
        string+="\""+(new String(this.word))+"\""+this.list;
        if (this.successor!=null) string+=this.successor;
        return string;
      public int treeNodeCount()
        /* students to complete */
      public String wordArray(int length)
        /* students to complete */

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    First read out how to ask questions in forums.
    (Living @ Virtual World)

Similar Threads

  1. Can somebody help me in my assignment
    By coolstruxx in forum NetBeans
    Replies: 0
    Last Post: 03-24-2009, 02:27 AM
  2. I am looking for help with an assignment
    By nanoo51969 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 10:41 PM
  3. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 05:23 AM
  4. First GUI Assignment
    By ljk8950 in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 08:29 AM
  5. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 09:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts