-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyStack.java
40 lines (38 loc) · 906 Bytes
/
MyStack.java
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
class GStack<T>{
int tos;
Object[] stck;
public GStack(){
tos=0;
stck=new Object[10];
}
public void push(T item){
if(tos==10){
return;
}
stck[tos]=item;
tos++;
}
public T pop(){
if(tos==0){
return null;
}
tos--;
return (T)stck[tos];
}
}
public class MyStack {
public static void main(String[] args){
GStack<String> stringStack = new GStack<String>();
stringStack.push("seoul");
stringStack.push("busan");
stringStack.push("LA");
for(int n=0;n<3;n++){
System.out.println(stringStack.pop());
}
GStack<Integer> intStack = new GStack<Integer>();
intStack.push(1);
intStack.push(3);
intStack.push(5);
for(int n=0;n<3;n++) System.out.println(intStack.pop());
}
}