@@ -104,7 +104,15 @@ public int get(int key) {
104104if (node ==null ) {
105105return -1 ;
106106 }else {
107- update (node );
107+
108+ /**Do two operations: this makes the process more clear:
109+ * remove the old node first, and then
110+ * just add the node again.
111+ * This will guarantee that this node will be at the latest position:
112+ * the most recently used position.*/
113+ remove (node );
114+ add (node );
115+
108116return node .value ;
109117 }
110118 }
@@ -133,14 +141,6 @@ public void set(int key, int value) {
133141 }
134142 }
135143
136- private void update (DoublyLinkedListPlusHashMapSolution .Node node ) {
137- /** this simplifies the process, just do two operations, remove the old node first, and then
138- just add the node again this will guarantee that this node will be at the latest position:
139- the most recently used position.*/
140- remove (node );
141- add (node );
142- }
143-
144144private void remove (DoublyLinkedListPlusHashMapSolution .Node node ) {
145145DoublyLinkedListPlusHashMapSolution .Node next =node .next ,prev =node .prev ;
146146prev .next =next ;