forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxyz.java1
52 lines (52 loc) · 915 Bytes
/
xyz.java1
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
class Stack
{
String st[]= new String[50];
int size,top,ctr;
Stack()
{
top=-1;
ctr=0;
}
Stack(int cap)
{
size=cap;
}
void pushname(String n)
{
if(top==size-1)
System.out.println("OVERFLOW");
else
{
top++;
st[top]=n;
ctr++;
}
}
String popname()
{
String v;
if(top==-1)
{
System.out.println("Underflow");
return("");
}
else
{
v=st[top];
top--;
ctr--;
return(v);
}
}
void display()
{
if(top==-1)
System.out.println("Underflow");
else
{
for(int i=top;i>0;i--)
System.out.println(st[i]);
System.out.println("NUMBER OF ELEMENTS IN THE STACK \t"+ctr);
}
}
}