forked from loopccoew/Buffer_3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckUpList.java
105 lines (89 loc) · 1.47 KB
/
CheckUpList.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
package loop;
class CheckNode {
Checkup cp;
CheckNode next,prev;
public CheckNode(Checkup cp)
{
next=prev=null;
this.cp=cp;
}
}
public class CheckUpList{
CheckNode head,tail;
public CheckUpList()
{
head=null;
tail=null;
}
public void Enqueue(Checkup cp)
{
CheckNode node=new CheckNode(cp);
if(head==null || tail==null)
{
head=node;
tail=node;
}
else if(head.cp.getPriority()<cp.getPriority())
{
head.next=node;
node.prev=head;
head=node;
}
else if(tail.cp.getPriority()>=cp.getPriority())
{
tail.prev=node;
node.next=tail;
tail=node;
}
else
{
CheckNode temp=tail;
while(temp!=null)
{
if(temp.cp.getPriority()>=cp.getPriority())
{
break;
}
temp=temp.next;
}
node.next=temp;
node.prev=temp.prev;
temp.prev.next=node;
temp.prev=node;
}
}
public Checkup Dequeue()
{
if(head==null)
{
return null;
}
CheckNode checkup=head;
head=head.next;
return checkup.cp;
}
public Patient getPatient(int index)
{
CheckNode temp=head;
int i=0;
while(temp!=null)
{
if(index==1)
{
break;
}
i++;
temp=temp.prev;
}
return temp.cp.getPatient();
}
public void print()
{
CheckNode temp=head;
while(temp!=null)
{
System.out.println(temp.cp.getPriority()+" "+temp.cp.getRecomendation());
temp=temp.prev;
}
}
}