import java.util.*;
public class CatDogAsylum {
public void func(int[] arr,int head,int y) {
if (y==0) {
return;
}
for (int i = y; i >head ; i--) {
arr[i] = arr[i-1];
}
}
public ArrayList<Integer> asylum(int[][] ope) {
if(ope ==null||ope.length==0) {
return null;
}
ArrayList<Integer> arrayList = new ArrayList<>();
int[] elem = new int[ope.length];
int head = 0;
int tail = 0;
for(int i =0;i<ope.length;i++) {
if(ope[i][0]==1) {
//add
elem[tail++] = ope[i][1];
} else if(ope[i][0]==2) {
//删除
if (tail == 0) {
}
if(ope[i][1] == 0) {
int ret = elem[head];
arrayList.add(ret);
head++;
} else if (ope[i][1] == 1) {
int j = 0;
for (j =head; j < tail; j++) {
if(elem[j]>0) {
int ret = elem[j];
arrayList.add(ret);
// 从 head 将其覆盖
func(elem,head,j);
head++;
break;
}
}
if(j==tail) {
}
} else if (ope[i][1]==-1) {
int j = 0;
for (j =head; j < tail; j++) {
if(elem[j] < 0) {
int ret = elem[j];
arrayList.add(ret);
// 从 head 将其覆盖
func(elem,head,j);
head++;
break;
}
}
if(j==tail) {
}
}
}
}
// write code here
return arrayList;
}
}