哈希表+二叉树

时间:2017-05-03 13:12:41

标签: java hash binary-tree

我现在已经看了2天了,此时我认为这比任何事情都更令人沮丧。我有一个Java哈希表和二叉树测试的应用程序,但是当我运行它时,我无法通过“System.out.println(”数据存储哈希表和/或二叉树“);”信息。这是我的主要方法的代码,就像我说它很可能非常简单。在此先感谢您的帮助。

public static void main(String[] args) {
    //LF: calls help text if requested or if invaild entry

    if (args.length == 0 || args[0].equals("help")) {  
        System.out.println("Data Store Hash Table and or Binary Tree");
    } else {
        String[] arg0_options = new String[] {"Hash Table", "Binary Tree"};

        if (Arrays.asList(arg0_options).contains(args[0])) {
            switch (args[0]) {
            case "Hash Table":  
                testHashTable(); //LF: tests the HASH table implementation
                break;
            case "Binary Tree":
                testBinaryTree();  //LF: test the BINARY tree implementation
                break;
            }

        } else {

            System.out.println("A defined data structure is needed, either a Hash Table or Binary Tree");
        }
    }

}

    //LF: Test HASH Table method
    //LF: Tests inserts, deletes and lookups of hash table

private static void testHashTable() {
    //LF: Create 13 hash buckets
    HashTable hash_table = new HashTable(13);

    hash_table.insert("Bob", "Smith", "555-235-1111", "bsmith@somewhere.com");
    hash_table.insert("Jane", "Williams", "555-235-1112", "jw@somthing.com" );
    hash_table.insert("Mohammed", "al-Salam", "555-235-1113", "mas@someplace.com");
    hash_table.insert("Pat", "Jones", "555-235-1114", "pjones@homesweethome.com");
    hash_table.insert("Billy", "Kidd", "555-235-1115", "billy_the_kid@nowhere.com");
    hash_table.insert("H", "Houdini", "555-235-1116", "houdini@noplace.com");
    hash_table.insert("Jack", "Jones", "555-235-1117", "jjones@hill.com");
    hash_table.insert("Jill", "Jones", "555-235-1118", "jillj@hill.com");
    hash_table.insert("John", "Doe", "555-235-1119", "jdoe@somedomain.com");
    hash_table.insert("Jane", "Doe", "555-235-1120", "jdoe@somedomain.com");

    hash_table.lookup("Pat", "Jones");
    hash_table.lookup("Billy", "Kidd");

    hash_table.delete("John", "Doe");

    hash_table.insert("Test", "Case", "555-235-1121", "Test_Case@testcase.com");
    hash_table.insert("Nadezhda", "Kanachekhovskaya", "555-235-1122", "dr.nadezhda.kanachekhovskaya@somehospital.moscow.ci.ru");
    hash_table.insert("Jo", "Wu", "555-235-1123", "wu@h.com");
    hash_table.insert("Millard", "Filmore", "555-235-1124", "millard@theactualwhitehouse.com");
    hash_table.insert("Bob", "vanDyke", "555-235-1125", "vandyke@nodomain.com");
    hash_table.insert("Upside", "Down", "555-235-1126", "upsidedown@rightsideup.com");

    hash_table.lookup("Jack", "Jones");
    hash_table.lookup("Nadezhda", "Kanachekhovskaya");

    hash_table.delete("Jill", "Jones");
    hash_table.delete("John", "Doe");

    hash_table.lookup("Jill", "Jones");
    hash_table.lookup("John", "Doe");

    System.out.println(hash_table);

}

//LF: Test BINARY tree method
//LF: Test inserts, deletes and lookups of the binary tree

private static void testBinaryTree() {

    BinaryTree binary_tree = new BinaryTree();

    binary_tree.insert("Bob", "Smith", "555-235-1111", "bsmith@somewhere.com");
    binary_tree.insert("Jane", "Williams", "555-235-1112", "jw@somthing.com" );
    binary_tree.insert("Mohammed", "al-Salam", "555-235-1113", "mas@someplace.com");
    binary_tree.insert("Pat", "Jones", "555-235-1114", "pjones@homesweethome.com");
    binary_tree.insert("Billy", "Kidd", "555-235-1115", "billy_the_kid@nowhere.com");
    binary_tree.insert("H", "Houdini", "555-235-1116", "houdini@noplace.com");
    binary_tree.insert("Jack", "Jones", "555-235-1117", "jjones@hill.com");
    binary_tree.insert("Jill", "Jones", "555-235-1118", "jillj@hill.com");
    binary_tree.insert("John", "Doe", "555-235-1119", "jdoe@somedomain.com");
    binary_tree.insert("Jane", "Doe", "555-235-1120", "jdoe@somedomain.com");

    binary_tree.lookup("Pat", "Jones");
    binary_tree.lookup("Billy", "Kidd");

    binary_tree.delete("John", "Doe");

    binary_tree.insert("Test", "Case", "555-235-1121", "Test_Case@testcase.com");
    binary_tree.insert("Nadezhda", "Kanachekhovskaya", "555-235-1122", "dr.nadezhda.kanachekhovskaya@somehospital.moscow.ci.ru");
    binary_tree.insert("Jo", "Wu", "555-235-1123", "wu@h.com");
    binary_tree.insert("Millard", "Filmore", "555-235-1124", "millard@theactualwhitehouse.com");
    binary_tree.insert("Bob", "vanDyke", "555-235-1125", "vandyke@nodomain.com");
    binary_tree.insert("Upside", "Down", "555-235-1126", "upsidedown@rightsideup.com");

    binary_tree.lookup("Jack", "Jones");
    binary_tree.lookup("Nadezhda", "Kanachekhovskaya");

    binary_tree.delete("Jill", "Jones");
    binary_tree.delete("John", "Doe");

    binary_tree.lookup("Jill", "Jones");
    binary_tree.lookup("John", "Doe");

}

}

0 个答案:

没有答案