高级农民
- 积分
- 4642
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2014-12-19
- 最后登录
- 1970-1-1
|
造福一下后来人。我的compFunction
- int compFunction(int code) {
- // Replace the following line with your solution.
- int a = 7;
- int b = 11;
- int p = 805306457;
- int hashCode = (a * code + b) % p;
- if(hashCode < 0) {hashCode += p;}
- hashCode = hashCode % bucketNum;
- return hashCode;
- }
复制代码
测试insert,find和remove的代码
- //Test hashTable methods
- table = new HashTableChained(numBoards);
- System.out.println("*************** size, isEmpty ***************");
- System.out.println("table's size is: " + table.size());
- System.out.println("table is Empty: " + table.isEmpty());
-
- System.out.println("*************** insert ***************");
- table.insert("1", "The first one");
- table.insert("2", "The second one");
- table.insert("3", "The third one");
- table.insert("4", "The fourth one");
- table.insert("5","The fifth one");
- System.out.println("table's size is: " + table.size());
- System.out.println("table is Empty: " + table.isEmpty());
- table.printBucketContent();
-
- System.out.println("*************** find, remove ***************");
- Entry e1 = table.find("1");
- if(e1 == null)
- System.err.println("find() has a problem.");
- else
- System.out.println("Found " + e1);
- Entry e2 = table.find("2");
- if(e2 == null)
- System.err.println("find() has a problem.");
- else
- System.out.println("Found " + e2);
- Entry e3 = table.find("10");
- if(e3 != null)
- System.err.println("find() has a problem.");
- else
- System.out.println("Cannot find 10");
-
- Entry e4 = table.remove("10");
- if(e4 != null)
- System.err.println("remove() has a problem.");
- else
- System.out.println("10 cannot be deleted.");
- Entry e5 = table.remove("4");
- if(e5 == null) {
- System.err.println("remove() has a problem");
- }
- else {
- System.out.println("Deleted is " + e5);
- }
- table.printBucketContent();
-
- System.out.println("*************** makeEmpty ***************");
- table.makeEmpty();
- table.printBucketNum();
复制代码 |
-
1.png
(15.39 KB, 下载次数: 0)
-
2.png
(21.78 KB, 下载次数: 0)
 组图打开中,请稍候......
|