interface IStack<T>{
T pop();
boolean push(T ob);
}
class MyStack<T> implements IStack<T>{
int tos;
Object [] stck;
public MyStack() {
tos = 0;
stck = new Object[10];
}
@Override
public T pop() {
// TODO Auto-generated method stub
if(tos == 0) return null;
tos--;
return (T)stck[tos];
}
@Override
public boolean push(T ob) {
// TODO Auto-generated method stub
if(tos == 10) return false;
stck[tos] = ob;
tos++;
return true;
}
}
public class StackMamager {
public static void main(String[] args) {
// TODO Auto-generated method stub
IStack<Integer> stack = new MyStack<Integer>();
for(int i=0;i<10;i++) stack.push(i);
while(true) {
Integer n = stack.pop();
if(n==null) break;
System.out.print(n+" ");
}
}
}
결과
9 8 7 6 5 4 3 2 1 0'명품JAVA프로그래밍 > 7장 제너릭과 컬렉션' 카테고리의 다른 글
| [명품JAVA프로그래밍] 7장 실습문제 11-2번 (0) | 2022.02.19 |
|---|---|
| [명품JAVA프로그래밍] 7장 실습문제 11-1번 (0) | 2022.02.18 |
| [명품JAVA프로그래밍] 7장 실습문제 8번 (0) | 2022.02.18 |
| [명품JAVA프로그래밍] 7장 실습문제 7번 (0) | 2022.02.18 |
| [명품JAVA프로그래밍] 7장 실습문제 6번 (0) | 2022.02.17 |