SquenceStack by java

 1 class SStack<Type> {
 2     Type[] data;
 3     int len;
 4     int sp;
 5     
 6     public SStack(Type[] d) {
 7         // TODO Auto-generated constructor stub
 8         data = d;
 9         sp = 0;
10         len = data.length;
11     }
12     
13     private boolean IsFull() {
14         return sp == len;
15     }
16     
17     private boolean IsEmpty() {
18         return sp == 0; 
19     }
20     
21     public boolean Push(Type d) {
22         if (IsFull())
23             return false;
24         
25         data[sp++] = d;
26         
27         return true;
28     }
29     
30     public Type Pop() {
31         if (IsEmpty())
32             return null;
33         
34         return data[--sp];
35     }
36     
37 }
38 
39 public class SquenceStack {
40     public static void main(String[] args) {
41         String[] str = {"hello", "word"};
42         String d;
43         
44         SStack<String> stk = new SStack<String>(str);
45     
46         for (String string : str) {
47             stk.Push(string);
48         }
49         
50         while ((d = stk.Pop()) != null)
51             System.out.print(d + " ");
52     }
53 }

posted on 2012-09-03 23:21  robin.he  阅读(165)  评论(0)    收藏  举报

导航