-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
86 lines (68 loc) · 1.33 KB
/
Copy pathMain.java
File metadata and controls
86 lines (68 loc) · 1.33 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Stack
{
int top;
int N;
int arr[];
public Stack()
{
top=0;
N=5;
arr = new int[N];
}
public Stack(int size)
{
top = 0;
N = size;
arr = new int[N];
}
public boolean push(int element)
{
if(top==N)
{
System.out.println("SORRY! The Stack is Full");
return false;
}
else
{
arr[top]=element;
top++;
return true;
}
}
public int pop()
{
int element_to_return = arr[top-1];
top--;
return element_to_return;
}
public boolean isEmpty()
{
if(top == 0)
return true;
else
return false;
}
public boolean isFull()
{
return top==N;
}
public String toString()
{
String stringElement = "";
for(int i=0;i<top;i++)
{
stringElement = stringElement+" "+String.valueOf(arr[i]);
}
return stringElement;
}
}
public class Main
{
public static void main(String[] args)
{
Stack s = new Stack(2);
s.push(20);
s.push(50);
System.out.println(s);
}
}