forked from loopccoew/Buffer_3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatientList.java
110 lines (91 loc) · 1.53 KB
/
PatientList.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
package loop;
class PNode
{
Patient Patient ;
PNode next,prev;
//Constructor
public PNode()
{
}
public PNode(Patient Patient) {
this.Patient = Patient;
next=null;
prev=null;
}
}
public class PatientList {
PNode head,tail;
public PatientList()
{
head=null;
tail=null;
}
public void Insert(Patient Patient)
{
PNode node=new PNode(Patient);
if(head==null || tail==null)
{
head=node;
tail=node;
}
else
{
head.next=node;
node.prev=head;
head=node;
}
}
public Patient searchById(String Id)
{
PNode temp=head;
while(temp!=null)
{
if(temp.Patient.getId().equals(Id))
{
return temp.Patient;
}
temp=temp.prev;
}
return null;
}
public void searchByName(String Name)
{
boolean b = false;
PNode temp=head;
while(temp!=null)
{
if(temp.Patient.getName().equals(Name))
{
System.out.println(temp.Patient);
b=true;
}
temp=temp.prev;
}
if(b==false)
{
System.out.println("Patient with this name is not available");
}
}
public int Size()
{
PNode temp=head;
int count=0;
while(temp!=null)
{
count++;
temp=temp.prev;
}
return count;
}
public void PrintData()
{
PNode temp=head;
int count=0;
while(temp!=null)
{
count++;
System.out.println(count+": "+temp.Patient.toString());
temp=temp.prev;
}
}
}