-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
51 lines (42 loc) · 696 Bytes
/
Copy pathStack.java
File metadata and controls
51 lines (42 loc) · 696 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
44
45
46
47
48
49
50
51
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Stack
{
int stack[];
int top;
int capacity;
public Stack(int setupCount)
{
stack = new int[setupCount];
capacity = setupCount;
top = -1;
}
public void add(int data)
{
if (top == capacity)
{
return;
}
top ++;
stack[top] = data;
}
public int pop()
{
if (top == -1) return -1;
int popT = stack[top];
top --;
return popT;
}
public static void main (String[] args)
{
Stack stack = new Stack(10);
stack.add(80);
stack.add(20);
stack.add(70);
stack.add(40);
stack.add(30);
System.out.println (stack.pop());
}
}