File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Data_Structure/src/chap4_Stacks_Queues Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ package chap4_Stacks_Queues ;
2+
3+ class StackX {
4+ private int maxSize ;
5+ private long [] stackArray ;
6+ private int top ;
7+
8+ public StackX (int s ) {
9+ maxSize = s ;
10+ stackArray = new long [maxSize ];
11+ top = -1 ;
12+ }
13+
14+ public void push (long j ) {
15+ stackArray [++top ] = j ;
16+ }
17+
18+ public long pop () {
19+ return stackArray [top --];
20+ }
21+
22+ public long peek () {
23+ return stackArray [top ];
24+ }
25+
26+ public boolean isEmpty () {
27+ return (top == -1 );
28+ }
29+
30+ public boolean isFull () {
31+ return (top == maxSize );
32+ }
33+ } //end class StackX
34+
35+ public class StackApp {
36+
37+ public static void main (String [] args ) {
38+ // TODO Auto-generated method stub
39+ StackX theStack = new StackX (10 );
40+ theStack .push (20 );
41+ theStack .push (40 );
42+ theStack .push (60 );
43+ theStack .push (80 );
44+
45+ while (!theStack .isEmpty ()) {
46+ long value = theStack .pop ();
47+ System .out .print (value + ", " );
48+ }
49+ System .out .println ("" );
50+ } //end main()
51+
52+ }
You can’t perform that action at this time.
0 commit comments