-
Notifications
You must be signed in to change notification settings - Fork 0
/
EndTermQ3.java
142 lines (134 loc) · 3.15 KB
/
EndTermQ3.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package JavaPrograms;
import java.net.SecureCacheResponse;
import java.util.Scanner;
interface OSProcesses
{
public void addProcess(int data);
public int deleteProcess();
public void show();
}
class LIFO implements OSProcesses
{
private int top;
int arr[] = new int[5];
public int getTop() {
return top;
}
public void setTop(int top) {
this.top = top;
}
public void addProcess(int data)
{
if(top!=5)
{
arr[top]=data;
top++;
}
else
System.out.println("Can't be added cause its full");
}
public int deleteProcess()
{
int data;
top--;
data=arr[top];
if(top!=0)
arr[top]=0;
else
System.out.println("Can't be removed cause its empty");
return data;
}
public void show()
{
System.out.println("Elements");
for(int k:arr)
{
System.out.print(k+" ");
}
System.out.println();
}
}
class FIFO implements OSProcesses
{
public int getFront() {
return front;
}
public void setFront(int front) {
this.front = front;
}
public int getrear() {
return rear;
}
public void setrear(int rear) {
this.rear = rear;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
private int front,rear,size;
int arr[] = new int[5];
public void addProcess(int data)
{
if(size!=5)
{
arr[rear]=data;
rear++;
size++;
}
else
System.out.println("can't be added cause its full");
}
public int deleteProcess()
{
int data;
data=arr[front];
if(size!=0)
{
arr[front]=0;
front++;
size--;
}
else
System.out.println("Can't be removed cause its empty");
return data;
}
public void show()
{
System.out.println("Elements");
for(int k:arr)
{
System.out.print(k+" ");
}
System.out.println();
}
}
public class EndTermQ3 {
public static void main(String arg[])
{
LIFO obj = new LIFO();
FIFO obj2 = new FIFO();
System.out.println("Enter the five element in LIFO implementation");
Scanner s = new Scanner(System.in);
for(int i=0;i<5;i++)
{
int x = s.nextInt();
obj.addProcess(x);
}
obj.show();
System.out.println("Removed element = "+obj.deleteProcess());
obj.show();
System.out.println("Enter the elements for FIFO implementation");
Scanner s1 = new Scanner(System.in);
for(int i=0;i<5;i++)
{
int y = s1.nextInt();
obj2.addProcess(y);
}
obj2.show();
System.out.println("Removed element = "+obj2.deleteProcess());
obj2.show();
}
}