-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStack.java
More file actions
43 lines (36 loc) · 921 Bytes
/
Copy pathMyStack.java
File metadata and controls
43 lines (36 loc) · 921 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
package generics;
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;
}
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("seould");
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());
}
}