Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- Scanner in = new Scanner(new File("input.txt"));
- PrintWriter pw = new PrintWriter("output.txt");
- My_Queue queue = new My_Queue();
- String a;
- do {
- a = in.next();
- switch (a) {
- case "push":
- queue.push(in.nextInt());
- pw.println("ok");
- break;
- case "pop":
- if (queue.size() == 0) pw.println("error");
- else pw.println(queue.pop());
- break;
- case "front":
- if (queue.size() == 0) pw.println("error");
- else pw.println(queue.peek());
- break;
- case "size":
- pw.println(queue.size());
- break;
- case "clear":
- queue.clear();
- pw.println("ok");
- break;
- }
- } while (!a.equals("exit"));
- pw.println("bye");
- in.close();
- pw.close();
- }
- static class My_Queue {
- private int[] array;
- private int top;
- private int bottom;
- public My_Queue() {
- array = new int[1000000];
- top = 0;
- bottom=0;
- }
- public void push(int q) {
- array[top++] = q;
- }
- public int size() {
- return top-bottom;
- }
- public int pop() {
- return array[bottom++];
- }
- public int peek() {
- return array[bottom];
- }
- public void clear() {
- top = 0;
- bottom = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement