From 668efe01fbf0eef16ba16706b1a9a8c4b034a1a6 Mon Sep 17 00:00:00 2001 From: Amaan-29 Date: Tue, 13 Jan 2026 16:13:44 -0500 Subject: [PATCH] Queue using stack HW --- .idea/.gitignore | 3 +++ .idea/codeStyles/Project.xml | 7 +++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++++ .idea/misc.xml | 6 +++++ .idea/modules.xml | 8 ++++++ .idea/vcs.xml | 6 +++++ Design-2.iml | 11 ++++++++ MyQueue.java | 38 ++++++++++++++++++++++++++++ 8 files changed, 84 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Design-2.iml create mode 100644 MyQueue.java 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(); + } +}