-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathDMuhammad
More file actions
76 lines (64 loc) · 1.7 KB
/
DMuhammad
File metadata and controls
76 lines (64 loc) · 1.7 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
class linkList{
public int nim;
public String nama;
public linkList next;
public linkList previous;
public linkList(int nim, String nama){
this.nim = nim;
this.nama = nama;
}
public void displayLink(){
System.out.println("\t" + nim + " " + nama);
}
}
class Queue{
private linkList first;
private linkList last;
public boolean isEmpty(){
return first == null;
}
public void insert(int nim, String nama){
linkList newList = new linkList(nim, nama);
if(isEmpty()){
first = newList;
}else{
last.next = newList;
newList.previous = last;
}
last = newList;
}
public linkList remove(){
linkList temp = first;
if(first.next == null){
last = null;
}else{
first.next.previous = null;
}
first = first.next;
return temp;
}
public void display(){
System.out.println("Queue (front-->rear): ");
linkList current = first;
while(current != null){
current.displayLink();
current = current.next;
}
System.out.println("");
}
}
public class QueueApp {
public static void main(String[] args) {
Queue theQueue = new Queue();
theQueue.insert(1665100, "Dee");
theQueue.insert(1665200, "Deaja");
theQueue.display();
theQueue.insert(1665300, "Ami");
theQueue.insert(1665400, "Haya");
theQueue.insert(1665500, "Yati");
theQueue.display();
theQueue.remove();
theQueue.remove();
theQueue.display();
}
}