@@ -0,0 +1,1180 @@
+// Java program to implement stack using a single queue%0A%0Aimport java.util.LinkedList;%0Aimport java.util.Queue;%0A%0Apublic class stack%0A%7B%0A%09Queue%3CInteger%3E q = new LinkedList%3CInteger%3E();%0A%09%0A%09// Push operation%0A%09void push(int val)%0A%09%7B%0A%09%09// get previous size of queue%0A%09%09int size = q.size();%0A%09%09%0A%09%09// Add current element%0A%09%09q.add(val);%0A%09%09%0A%09%09// Pop (or Dequeue) all previous%0A%09%09// elements and put them after current%0A%09%09// element%0A%09%09for (int i = 0; i %3C size; i++)%0A%09%09%7B%0A%09%09%09// this will add front element into%0A%09%09%09// rear of queue%0A%09%09%09int x = q.remove();%0A%09%09%09q.add(x);%0A%09%09%7D%0A%09%7D%0A%09%0A%09// Removes the top element%0A%09int pop()%0A%09%7B%0A%09%09if (q.isEmpty())%0A%09%09%7B%0A%09%09%09System.out.println(%22No elements%22);%0A%09%09%09return -1;%0A%09%09%7D%0A%09%09int x = q.remove();%0A%09%09return x;%0A%09%7D%0A%09%0A%09// Returns top of stack%0A%09int top()%0A%09%7B%0A%09%09if (q.isEmpty())%0A%09%09%09return -1;%0A%09%09return q.peek();%0A%09%7D%0A%09%0A%09// Returns true if Stack is empty else false%0A%09boolean isEmpty()%0A%09%7B%0A%09%09return q.isEmpty();%0A%09%7D%0A%0A%09// Driver program to test above methods%0A%09public static void main(String%5B%5D args)%0A%09%7B%0A%09%09stack s = new stack();%0A%09%09s.push(10);%0A%09%09s.push(20);%0A%09%09System.out.println(%22Top element :%22 + s.top());%0A%09%09s.pop();%0A%09%09s.push(30);%0A%09%09s.pop();%0A%09%09System.out.println(%22Top element :%22 + s.top());%0A%09%7D%0A%7D%0A%0A

Create StackUsingQueue.java