Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- class queue{
- static int n=201;
- int[] a=new int[n];
- int r=-1,f=-1;
- void enqueue(int x){
- r=(r+1)%n;
- a[r%n]=x;
- }
- int dequeue(){
- if(r%n==f%n)
- return 0;
- int z=f;
- f=(f+1)%n;
- return a[(1+z)%n];
- }
- int front(){
- return a[(f+1)%n];
- }
- int rear(){
- return a[r];
- }
- int size(){
- return (r-f+n)%n;
- }
- }
- public class Solution {
- static int n=201;
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- queue q=new queue();
- String p=" ";
- while(t>0){
- String st=sc.next();
- if(st.equals("Enqueue")){
- int x=sc.nextInt();
- q.enqueue(x);
- }
- else{
- int tz=q.dequeue();
- if(p.equals("Enqueue") && tz==0){
- System.out.println(n);
- }
- else if(tz==0){
- System.out.println("Empty");
- }
- else
- System.out.println(tz);
- }
- p=st;
- t--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement