-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack구현.java
More file actions
46 lines (38 loc) · 933 Bytes
/
Stack구현.java
File metadata and controls
46 lines (38 loc) · 933 Bytes
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
38
39
40
41
42
43
44
45
46
package channel;
import java.util.concurrent.ThreadPoolExecutor;
public class IntStack {
private int[] stack;
private int top = -1;
public IntStack(int capacity) {
//stack 용량 생성
if(capacity <= 0) throw new IllegalArgumentException("0 이하의 용량은 불가능합니다.");
stack = new int[capacity];
}
public int pop() {
return stack[--top];
}
public int peak() {
return stack[top];
}
public void push(int x) {
stack[++top] = x;
}
public boolean isEmpty() {
return top == -1;
}
public int size() {
return top+1;
}
public static void main(String[] args) {
IntStack stack = new IntStack(10);
stack.push(-1);
stack.push(2);
stack.push(3);
stack.pop();
System.out.println(stack.toString());
System.out.println(stack.isEmpty());
System.out.println(stack.size());
stack.pop();
System.out.println(stack.peak());
}
}