Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. // File ChainedTableDemonstration.java
  2. // This small demonstration program shows how to use the ChainedTable class
  3.  
  4. public class ChainedTableDemonstration
  5. {
  6. public static void main(String[ ] args)
  7. {
  8. final int SIZE = 10; // The size of the demonstration Table
  9.  
  10. ChainedTable table = new ChainedTable(SIZE);
  11. table.put(43210, "Sally Adams, 845-123-4567");
  12. table.put(55555, "Cathy Baker, 255-765-4321");
  13. table.put(12345, "Lisa Cook, 255-123-4567");
  14. table.put(98765, "Jessica Green, 255-123-4567");
  15. table.put(22222, "Jerry Jefferson, 914-111-2222");
  16. table.put(21212, "Susan Rosenburg, 914-222-1111");
  17. table.put(33333, "John Silverburg, 845-462-2222");
  18. table.put(56789, "Frank Smith, 212-888-8888");
  19. table.put(11119, "Scott Walder, 212-999-9999");
  20. table.put(99999, "Peter Young, 212-000-0000");
  21. table.show();
  22.  
  23. int key;
  24. ChainedHashNode cursor;
  25.  
  26. key = 12345;
  27. if (table.containsKey(key))
  28. System.out.println(key + " is in the hash table.");
  29. else
  30. System.out.println(key + " is not in the hash table.");
  31.  
  32. key = 12340;
  33. if (table.containsKey(key))
  34. System.out.println(key + " is in the hash table.");
  35. else
  36. System.out.println(key + " is not in the hash table.");
  37.  
  38. key=56789;
  39. cursor = (ChainedHashNode)table.get(key);
  40. if (cursor == null)
  41. System.out.println(key + " is not in the hash table.");
  42. else
  43. System.out.println(key + " is in the hash table with data "
  44. + "\"" + cursor.element + "\"");
  45.  
  46. key=66666;
  47. cursor = (ChainedHashNode)table.get(key);
  48. if (cursor == null)
  49. System.out.println(key + " is not in the hash table.");
  50. else
  51. System.out.println(key + " is in the hash table with data "
  52. + "\"" + cursor.element + "\"");
  53.  
  54. table.remove(21212);
  55. table.remove(12345);
  56. table.remove(56789);
  57. table.remove(00000);
  58. table.show();
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement