728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import java.util.Stack; /* * Stack Class * 1. LIFO (Last In First Out) 형태의 임시버퍼 * : 버퍼에 임시로 자료를 저장하였다가 필요할 때 꺼내 쓴다. * : 요청시 가장 최근에 보관한 자료부터 꺼낸다. * * public void push(Element data); //순차보관 * public Element pop(); //값을 반환(최근 저장) * public Element peek(); //값을 참조(최근 저장) * public boolean empty(); //비어있는지 체크 * public int search(Element data); //data를 보관한 순번 반환 */ public class StackMain { public static void main(String[] args) { Stack stack = new Stack(); stack.push(7); //7 stack.push(5); //7, 5 stack.push(3); //7, 5, 3 System.out.println(stack.pop()); //3 System.out.println(stack.pop()); //5 stack.push(9); stack.push(11); System.out.println(stack.peek()); //11 System.out.println(stack.pop()); //11 System.out.println(stack.search(9)); // 1번째 while(stack.empty() == false) { System.out.println(stack.pop()); } } } | cs |
반응형
'SKILL > JAVA' 카테고리의 다른 글
자바 메모리 (0) | 2017.12.20 |
---|---|
자바 Queue 기본 예제 (0) | 2017.12.19 |
자바 IP관련 클래스 : InetAddress (0) | 2017.12.19 |
자바 Vector연습예제 (0) | 2017.12.19 |
자바 로또 번호 생성 게임예제02 (0) | 2017.12.19 |