diff --git a/MyHashMap.java b/MyHashMap.java new file mode 100644 index 00000000..ebfdf18b --- /dev/null +++ b/MyHashMap.java @@ -0,0 +1,20 @@ +class MyHashMap { +Map m; + + public MyHashMap() { + m=new HashMap<>(); + } + + public void put(int key, int value) { + m.put(key, value); + } + + public int get(int key) { + return (m.containsKey(key)) ? m.get(key) : -1; + } + + public void remove(int key) { + m.remove(key); + } +} + diff --git a/MyQueue.java b/MyQueue.java new file mode 100644 index 00000000..c71bc818 --- /dev/null +++ b/MyQueue.java @@ -0,0 +1,43 @@ +class MyQueue { +Stack in; +Stack t; + + public MyQueue() { + in=new Stack<>(); + t= new Stack<>(); + } + + public void push(int x) { + in.push(x); + } + + public int pop() { + if(t.isEmpty()) + { + while(!in.isEmpty()) +{t.push(in.pop());} + } + + return t.pop(); + } + + public int peek() { + if(t.isEmpty()) + { + while(!in.isEmpty()) + + { + t.push(in.pop()); + } + + + } + return t.peek(); + + } + + public boolean empty() { + return in.isEmpty() && t.isEmpty(); + } +} +