-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLRUCache.java
More file actions
60 lines (50 loc) · 1.14 KB
/
Copy pathLRUCache.java
File metadata and controls
60 lines (50 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package queue;
import java.util.*;
class lruNode{
String data;
lruNode next;
lruNode prev;
lruNode(String x){
data=x;
next=null;
prev=null;
}
}
public class LRUCache {
lruNode head;
Map<Integer,Integer> map;
int capacity;
/*Inititalize an LRU cache with size N */
public LRUCache(int N) {
}
/*Returns the value of the key x if
present else returns -1 */
public int get(int x) {
//Your code here
}
/*Sets the key x with value y in the LRU cache */
public void set(int x, int y) {
//Your code here
}
public void addToLRU(String new_item){
lruNode new_node = new lruNode(new_item);
lruNode curr=head;
if(head==null){
head=new_node;
}
else{
while(curr!=null){
curr=curr.next;
}
curr=new_node;
new_node.next=null;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
LRUCache lc = new LRUCache(3);
lc.addToLRU("chocolate");
lc.addToLRU("vanilla");
lc.addToLRU("strawberry");
}
}