-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathass1_5.java
77 lines (64 loc) · 1.45 KB
/
ass1_5.java
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
import java.util.Scanner;
class stack
{
int stk[]=new int[100];
int tos;
stack()
{
tos=-1;
}
void push(int d_data)
{
stk[++tos]=d_data;
System.out.println("Your element "+d_data+" successfully inserted");
}
void pop()
{
System.out.println("Your element "+stk[tos--]+" successfully deleted");
}
void display()
{
int temp;
System.out.println("Your Stack is: ");
for(temp=tos;temp>0;temp--)
System.out.print(stk[temp]+" ->");
System.out.print(stk[temp]);
}
}
class ass1_5
{
public static void main(String s[])
{
int ch,data;
char c;
stack st=new stack();
Scanner sc=new Scanner(System.in);
do
{
System.out.println("This is a program of stack.");
System.out.println("1. Push Operation");
System.out.println("2. Pop Operation");
System.out.println("3. Display");
System.out.print("Give your choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println("\nYou selected Push operation");
System.out.print("Enter Data: ");
data=sc.nextInt();
st.push(data);
break;
case 2: System.out.println("\nYou selected Pop operation");
st.pop();
break;
case 3: System.out.println("\nYou selected Display Function");
st.display();
break;
default: System.out.println("Wrong Choice!!");
}
System.out.print("\nDo you want to continue ?(y/n): ");
sc.nextLine();
c=sc.next().charAt(0);
}while(c=='y');
}
}