Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
queue_using_stack
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { class MyQueue { Stack<Integer> temp = new Stack<Integer>(); Stack<Integer> value = new Stack<Integer>(); // Push element x to the back of queue. public void push(int x) { if(value.isEmpty()){ value.push(x); }else{ while(!value.isEmpty()){ temp.push(value.pop()); } value.push(x); while(!temp.isEmpty()){ value.push(temp.pop()); } } } // Removes the element from in front of queue. public void pop() { value.pop(); } // Get the front element. public int peek() { return value.peek(); } // Return whether the queue is empty. public boolean empty() { return value.isEmpty(); } } } }
run
|
edit
|
history
|
help
0
get top k frequent elements ( Priority Queue implementation )
Central Inteligence Agency
Java recursive test
String object comparision
Problem: rstring
3.A
Speed
variable1
evenloop
Count Islands