Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author jiyou_000
- */
- import java.util.Stack;
- public class Queue <T>
- {
- public Stack<T> s;
- public Queue()
- {
- s = new Stack<>();
- }
- public boolean empty()
- {
- return s.empty();
- }
- public void enqueue(T a)
- {
- if (s.empty())
- {
- s.push(a);
- }
- else
- {
- Stack<T> tmp = new Stack<>();
- while (!s.empty())
- {
- tmp.push(s.pop());
- }
- s.push(a);
- while (!tmp.empty())
- {
- s.push(tmp.pop());
- }
- }
- }
- public void dequeue() throws Exception
- {
- if (empty())
- {
- throw new Exception();
- }
- else
- {
- s.pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement