Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita369814

Browse files
edit 146
1 parent518f2a0 commita369814

File tree

1 file changed

+12
-13
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-13
lines changed

‎src/main/java/com/fishercoder/solutions/_146.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ private class Node {
8484
privateintcapacity;
8585
privateintcount;
8686
privateDoublyLinkedListPlusHashMapSolution.Nodehead,tail;
87-
privateMap<Integer,DoublyLinkedListPlusHashMapSolution.Node>map;// ATTN: the value should be Node type! This is the whole point
88-
// of having a class called Node!
87+
privateMap<Integer,DoublyLinkedListPlusHashMapSolution.Node>map;
88+
//ATTN: the value should be Node type! This is the whole pointof having a class called Node!
8989

9090
publicDoublyLinkedListPlusHashMapSolution(intcapacity) {
9191
this.capacity =capacity;
@@ -99,8 +99,8 @@ public DoublyLinkedListPlusHashMapSolution(int capacity) {
9999
}
100100

101101
publicintget(intkey) {
102-
DoublyLinkedListPlusHashMapSolution.Nodenode =map.get(key);// HashMap allows value to be null, this is superior than
103-
// HashTable!
102+
DoublyLinkedListPlusHashMapSolution.Nodenode =map.get(key);
103+
//HashMap allows value to be null, this is superior thanHashTable!
104104
if (node ==null) {
105105
return -1;
106106
}else {
@@ -118,9 +118,9 @@ public void set(int key, int value) {
118118
count++;
119119

120120
if (count >capacity) {
121-
// ATTN: It's tail.prev, not tail, because tail is always an invalid node, it
122-
//doesn't contain anything, it's always the tail.prev that is the last node in the
123-
//cache
121+
/** ATTN: It's tail.prev, not tail, because tail is always an invalid node, it
122+
doesn't contain anything, it's always the tail.prev that is the last node in the
123+
cache*/
124124
DoublyLinkedListPlusHashMapSolution.NodetoDelete =tail.prev;
125125
map.remove(toDelete.key);
126126
remove(toDelete);
@@ -134,10 +134,9 @@ public void set(int key, int value) {
134134
}
135135

136136
privatevoidupdate(DoublyLinkedListPlusHashMapSolution.Nodenode) {
137-
// this simplifies the process, just do two operations, remove the old node first, and then
138-
// just add the node again
139-
// this will guarantee that this node will be at the latest position: the most recently used
140-
// position.
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.*/
141140
remove(node);
142141
add(node);
143142
}
@@ -148,8 +147,8 @@ private void remove(DoublyLinkedListPlusHashMapSolution.Node node) {
148147
next.prev =prev;
149148
}
150149

151-
privatevoidadd(DoublyLinkedListPlusHashMapSolution.Nodenode) {// ATTN: we'll always add the node into the first position:
152-
// head.next!!!!
150+
privatevoidadd(DoublyLinkedListPlusHashMapSolution.Nodenode) {
151+
//ATTN: we'll always add the node into the first position:head.next!!!!
153152
DoublyLinkedListPlusHashMapSolution.Nodenext =head.next;
154153
head.next =node;
155154
node.next =next;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp