diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..f5bd2dfe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..ba7d4bd5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Design-2.iml b/Design-2.iml new file mode 100644 index 00000000..56014c63 --- /dev/null +++ b/Design-2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MyQueue.java b/MyQueue.java new file mode 100644 index 00000000..6a5b0c4e --- /dev/null +++ b/MyQueue.java @@ -0,0 +1,38 @@ +import java.util.Stack; + +public class MyQueue { + + private Stack in; + private Stack out; + + public MyQueue() { + this.in = new Stack<>(); + this.out = new Stack<>(); + } + + public void push(int x) { + in.push(x); //add elements in IN stack + } + + public int pop() { + if(out.isEmpty()){ + while(!in.isEmpty()){ + out.push(in.pop()); + } + } + return out.pop(); + } + + public int peek() { + if(out.isEmpty()){ + while(!in.isEmpty()){ + out.push(in.pop()); + } + } + return out.peek(); + } + + public boolean empty() { + return in.isEmpty() && out.isEmpty(); + } +}