[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Array+Binary Tree+ HashTable

Posted on 2008-01-31
3
Medium Priority
?
327 Views
Last Modified: 2012-05-05
Hey,
I have to implements a program which will take two lists of strings and the strings of the first list should be placed in an UNORDERED array, to an ordered tree and to a hashTable.
and then each word in the second list should be checked if it is contained in the unordered array, binary tree, hashtable.

Can anyone give me a clue how to start this program ?? [ or if its something already made it should be much better :p]

thanks in advance !
0
Comment
Question by:perdoname_
  • 2
3 Comments
 
LVL 20

Expert Comment

by:gatorvip
ID: 20789523
where is the difficulty?

If I'm interpreting your post correctly, you will insert the contents of the first list into 3 different data structures, so...

-your unordered array will have the same length as the first list of strings
-loop through the list, and at each step add the current string into the array, the BT and the hashtable.
0
 

Author Comment

by:perdoname_
ID: 20803115
thats what i did up to now :/
import java.util.*;
 
public class ArrayTreeHash 
{
 
 
    
    //unordered array
   // class UnorderedArrayList
   // {
        
     //   var unorderedArr: Array = new Arry();
   // }
        
    //binary tree
 
 
 
 
 
class TreeNode {
 
    String data;
    TreeNode left;   
    TreeNode right;   
 
 
 
 
   
} 
 
 
 
public class BinaryTreeString {
 
    TreeNode root = null;    
    int numItems = 0;        
 
    public void add (String data)
    {
 
        if (root == null) {
            root = new TreeNode ();
            root.data = data;
            numItems ++;
            return;
        }
        
 
        if ( contains (data) ) {
 
            return;
        }
        
 
        recursiveInsert (root, data);
        
        numItems ++;
    }
 
    
    void recursiveInsert (TreeNode node, String data)
    {
 
        if ( data.compareTo (node.data) < 0 ) {
 
            if (node.left != null) {
                recursiveInsert (node.left, data);
            }
            else {
                node.left = new TreeNode ();
                node.left.data = data;
            }
            
        }
 
        else {
 
            if (node.right != null) {
                recursiveInsert (node.right, data);
            }
            else {
                node.right = new TreeNode ();
                node.right.data = data;
            }
        }
        
    }
    
    
    //hashTable
    class HashTable
    {
        Map<String, list1> data = new HasMap<String, list1>();
        
    }
}
}
 
 
 
class BinaryTreeStringExample 
//extends ArrayTreeHash {
{
 
    public static void main (String[] argv)
    {
        String [] list1 = {"java","hello","fight"};
 
        BinaryTreeString tree = new BinaryTreeString ();
 
            //
            //
            
 
    }
 
}
   

Open in new window

0
 
LVL 20

Accepted Solution

by:
gatorvip earned 1500 total points
ID: 20835756
from a general point of view, I would use 4 classes.

1. Entry class
- contains the 2 lists of strings
- constructs one instance of each class (Arr, BT, HT) based on the first list of strings
- creates a loop where in each iteration, you take the next word in the second list of strings. Then you call the method "has" in each of the other 3 instances (Arr, BT, HT) to see whether that word is contained in them

2. Array
- takes one parameter as input (list of strings), either in the constructor or in a helper method, and populates its internal fields based on that parameter
- contains one public method, let's call it   has(String s)  which returns true if the instance contains s
3. Binary Tree
- takes one parameter as input (list of strings), either in the constructor or in a helper method, and populates its internal fields based on that parameter
- contains one public method, let's call it   has(String s)  which returns true if the instance contains s
4. HashTable
- takes one parameter as input (list of strings), either in the constructor or in a helper method, and populates its internal fields based on that parameter
- contains one public method, let's call it   has(String s)  which returns true if the instance contains s
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question