public static Queue1 mirror(Queue1 s){
int len = s.getSize();
Queue1 ret = new Queue1(s.getSize());
Queue1 tmp = new Queue1(s.getSize());
while(ret.getSize()!=len){
while(s.getSize()>1) tmp.insert(s.remove());
ret.insert(s.remove());
while(tmp.getSize()>1) s.insert(tmp.remove());
ret.insert(tmp.remove());
}
return ret;
}
내 구현을 얻기 제거 방법 :큐만 사용하여 큐를 반전합니다. indexofbound 예외를 삽입의
public void insert(int x){
if(rear == maxsize-1) rear = -1;
arr[++rear] = x;
count++;
}
public int remove(){
int tmp = arr[front++];
if(front==maxsize) front = 0;
count--;
return tmp;
}
내가 s.getSize()+2
에 Tmp
의 크기를 증가,이 경우는 0을 출력하지 않는 코드가 작동하지 않습니다.
누군가가 진행 상황을 설명해 주시겠습니까?
해당 스 니펫 중 어느 것이 작동하지 않습니까? 무엇이 효과가 있을까요? – Makoto