자료구조
스택 / Stack
iIxmont
2017. 10. 19. 15:09
안녕하세요 이번 글에서는 스택에 대해서 알아보도록 하겠습니다
스택 : 순서가 있는 데이터의 결합 , LIFO 방식으로 데이터를 저장하고 빼낸다
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
import java.util.Stack;
class Coin{
private int value;
public Coin(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public class StackTest {
public static void main(String[] args) {
Stack<Coin> coinBox = new Stack<Coin>();
coinBox.push(new Coin(100));
coinBox.push(new Coin(50));
coinBox.push(new Coin(500));
coinBox.push(new Coin(10));
while (!coinBox.isEmpty()) {
Coin coin = coinBox.pop();
System.out.println("꺼낸 동전 : "+coin.getValue());
}
}
} |
cs |