신규 블로그를 만들었습니다!

2020년 이후부터는 아래 블로그에서 활동합니다.

댓글로 질문 주셔도 확인하기 어려울 수 있습니다.

>> https://bluemiv.tistory.com/
package stack;

import java.util.ArrayList;

public class Stack {

    private ArrayList<Object> buf = new ArrayList<Object>();
    private int top = -1;
    
    void push(Object item){
        buf.add(item);
        top++;
    }
    
    Object peek() {
        // 꺼내오기만 함
        if(!isEmpty()) {
            // 버퍼에 값이 있을때만
            Object result = buf.get(top);
            return result;
        }
        return null;
    }
    
    Object pop() {
        // 꺼내오고 지움
        if(!isEmpty()) {
            Object result = buf.get(top);
            buf.remove(top);
            top--;
            return result;
        }
        return null;
    }
    
    void delete() {
        if(!isEmpty()) {
            buf.remove(top);
            top--;
        }
    }
    
    boolean isEmpty() {
        if(buf.isEmpty()) {
            return true;
        }
        return false;
    }
}​

 

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기