You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privateListNoderemoveLast() {//remove last node from LinkedList
79
79
ListNodenode = this.tail;
80
80
if (this.head == this.tail)
81
81
this.head = this.tail = null;
@@ -87,7 +87,7 @@ private ListNode removeLast() {
87
87
returnnode;
88
88
}
89
89
90
-
privateListNoderemove(ListNodenode) {
90
+
privateListNoderemove(ListNodenode) {//remove the node
91
91
if (node == this.head)
92
92
returnremoveFirst();
93
93
elseif (node == this.tail)
@@ -104,26 +104,26 @@ else if (node == this.tail)
104
104
}
105
105
}
106
106
107
-
privatevoidmakeRecent(ListNodenode) {
107
+
privatevoidmakeRecent(ListNodenode) {// in this we move the node to the front of linkedlist
108
108
if (node == this.tail)
109
109
return;
110
110
111
111
remove(node);
112
112
addLast(node);
113
113
}
114
114
115
-
publicintget(intkey) {
116
-
if (!map.containsKey(key))
115
+
publicintget(intkey) {// get the value and add in the linkedlist
116
+
if (!map.containsKey(key))//if value is not present in the linked list then return -1
117
117
return -1;
118
118
119
119
ListNodenode = map.get(key);
120
120
makeRecent(node);
121
121
returnnode.value;
122
122
}
123
123
124
-
publicvoidput(intkey, intvalue) {
125
-
if (map.containsKey(key)) {
126
-
ListNodenode = map.get(key);
124
+
publicvoidput(intkey, intvalue) {//in this function whenever we put a value first we will check that whether that value is present or not in an hashmap
125
+
if (map.containsKey(key)) {
126
+
ListNodenode = map.get(key);// if value is present then we will update the value of the node
0 commit comments