Stack (스택)
1. 스택(Stack)
- 후입선출 (Last In First Out; LIFO) 자료구조
- 마지막에 들어온 데이터가 먼저 나가는 구조
 
 - 데이터가 입력된 순서의 역순으로 처리되어야 할 때 사용
- ex) 함수 콜 스택, 수식 계산, 인터럽트 처리
 
 
2. 스택 기본 구조
- 후입 선출 구조
 - 기본적으로 데이터 추가, 꺼내기, 스택 공간 확인 동작으로 이루어짐
 
(실습 : stack)
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
// 선형 자료구조 - 배열
import java.util.Stack;
public class Main {
    public static void main(String[] args) {
        Stack stack = new Stack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        System.out.println(stack);
        System.out.println(stack.pop());
        System.out.println(stack);
        System.out.println(stack.pop());
        System.out.println(stack);
        System.out.println(stack.peek());
        System.out.println(stack);
        System.out.println(stack.contains(1));
        System.out.println(stack.size());
        System.out.println(stack.empty());
        stack.clear();
        System.out.println(stack);
    }
}
 This post is licensed under  CC BY 4.0  by the author.