└── Drill06.java /Drill06.java: -------------------------------------------------------------------------------- 1 | public class Drill06 { 2 | 3 | // Given a generic HashNode as a parameter 4 | // return the value in the HashNode. 5 | public static V returnValue(HashNode node) { 6 | return node.getValue(); 7 | } 8 | 9 | // Given a generic HashNode as a parameter 10 | // return the key in the HashNode. 11 | public static K returnKey(HashNode node) { 12 | return node.getKey(); 13 | } 14 | 15 | // In the singly-linked list of generic HashNodes 16 | // that starts with the given node, return the value 17 | // in the last node. 18 | public static V findLastVal(HashNode first) { 19 | while (first.getNext() != null) { 20 | first = first.getNext(); 21 | } 22 | return first.getValue(); 23 | } 24 | 25 | // In the singly-linked list of generic HashNodes that starts 26 | // with the given node, return the indexed node. The first node is 27 | // index 0, then next index 1, etc. 28 | public static HashNode findNodeByIndex(HashNode first, 29 | int index) { 30 | for (int i = 0; i < index; i++) { 31 | first = first.getNext(); 32 | } 33 | return first; 34 | } 35 | 36 | // Count all of the nodes in the given singly-linked list of 37 | // generic HashNodes that starts with the given node. 38 | public static int countNodes(HashNode first) { 39 | int count = 1; 40 | if (first == null) { 41 | return 0; 42 | } 43 | while (first.getNext() != null) { 44 | count++; 45 | first = first.getNext(); 46 | } 47 | return count; 48 | } 49 | 50 | } 51 | --------------------------------------------------------------------------------