diff --git a/waiting_room/WaitingRoom/Node.cs b/waiting_room/WaitingRoom/Node.cs
index 7bcec34..b1f3c09 100644
--- a/waiting_room/WaitingRoom/Node.cs
+++ b/waiting_room/WaitingRoom/Node.cs
@@ -6,5 +6,11 @@
///
public sealed class Node
{
- // TODO
+ public Patient Data { get; }
+ public Node? Next { get; set; }
+
+ public Node(Patient patient)
+ {
+ Data = patient;
+ }
}
\ No newline at end of file
diff --git a/waiting_room/WaitingRoom/Patient.cs b/waiting_room/WaitingRoom/Patient.cs
index 0b2b66f..83b9831 100644
--- a/waiting_room/WaitingRoom/Patient.cs
+++ b/waiting_room/WaitingRoom/Patient.cs
@@ -5,7 +5,18 @@
///
public sealed class Patient
{
- // TODO ctor
+ public Patient(string name, DateTime arrival)
+ {
+ Name = name;
+ Arrival = arrival;
+ }
+
+ public Patient(string name, DateTime arrival, bool isEmergency)
+ {
+ Name = name;
+ Arrival = arrival;
+ IsEmergency = isEmergency;
+ }
///
/// Gets the name of the patient
diff --git a/waiting_room/WaitingRoom/PatientQueue.cs b/waiting_room/WaitingRoom/PatientQueue.cs
index 32f43d4..ba4c372 100644
--- a/waiting_room/WaitingRoom/PatientQueue.cs
+++ b/waiting_room/WaitingRoom/PatientQueue.cs
@@ -6,7 +6,7 @@
///
public sealed class PatientQueue
{
- //private Node? _head;
+ private Node? _head;
///
/// Gets the number of patients currently waiting in this queue
@@ -20,7 +20,25 @@ public sealed class PatientQueue
/// Patient to add to the queue
public void Enqueue(Patient patient)
{
- // TODO
+ var newNode = new Node(patient);
+
+ if (_head == null || patient.Arrival < _head.Data.Arrival)
+ {
+ newNode.Next = _head;
+ _head = newNode;
+ Size++;
+ return;
+ }
+
+ var current = _head;
+ while (current.Next != null && current.Next.Data.Arrival <= patient.Arrival)
+ {
+ current = current.Next;
+ }
+
+ newNode.Next = current.Next;
+ current.Next = newNode;
+ Size++;
}
///
@@ -29,8 +47,15 @@ public sealed class PatientQueue
/// The next patient to be treated; null if no patient is waiting
public Patient? Dequeue()
{
- // TODO
- return null;
+ if (_head == null)
+ {
+ return null;
+ }
+
+ var patient = _head.Data;
+ _head = _head.Next;
+ Size--;
+ return patient;
}
///
@@ -41,7 +66,31 @@ public sealed class PatientQueue
/// True if the patient could be removed; false otherwise
public bool Remove(Patient patient)
{
- // TODO
- return false;
+ if (_head == null)
+ {
+ return false;
+ }
+
+ if (_head.Data == patient)
+ {
+ _head = _head.Next;
+ Size--;
+ return true;
+ }
+
+ var current = _head;
+ while (current.Next != null && current.Next.Data != patient)
+ {
+ current = current.Next;
+ }
+
+ if (current.Next == null)
+ {
+ return false;
+ }
+
+ current.Next = current.Next.Next;
+ Size--;
+ return true;
}
}
\ No newline at end of file
diff --git a/waiting_room/WaitingRoom/WaitingRoom.cs b/waiting_room/WaitingRoom/WaitingRoom.cs
index 077982d..a49be65 100644
--- a/waiting_room/WaitingRoom/WaitingRoom.cs
+++ b/waiting_room/WaitingRoom/WaitingRoom.cs
@@ -14,20 +14,17 @@ public sealed class WaitingRoom
///
/// Gets the current number of emergency patients waiting
///
- // TODO
- public int CountEmergency => -1;
+ public int CountEmergency => _emergencyQueue.Size;
///
/// Gets the current number of normal patients waiting
///
- // TODO
- public int CountNormal => -1;
+ public int CountNormal => _normalQueue.Size;
///
/// Gets the current number of all patients waiting
///
- // TODO
- public int CountAll => -1;
+ public int CountAll => CountEmergency + CountNormal;
///
/// Creates a string representation of the waiting room, showing statistics
@@ -43,15 +40,25 @@ public sealed class WaitingRoom
/// Patient to admit
public void AddPatient(Patient patient)
{
- // TODO
+ if (patient.IsEmergency)
+ {
+ _emergencyQueue.Enqueue(patient);
+ }
+ else
+ {
+ _normalQueue.Enqueue(patient);
+ }
}
///
/// Returns the next patient to be treated, removing it from its waiting queue
///
/// Next patient to treat, if any
- // TODO
- public Patient? Next() => null;
+ public Patient? Next()
+ {
+ var emergency = _emergencyQueue.Dequeue();
+ return emergency ?? _normalQueue.Dequeue();
+ }
///
/// Promotes a patient to be an emergency case.
@@ -60,6 +67,12 @@ public sealed class WaitingRoom
/// Patient to declare an emergency for
public void SetPatientToEmergency(Patient patient)
{
- // TODO
+ if (!_normalQueue.Remove(patient))
+ {
+ return;
+ }
+
+ patient.IsEmergency = true;
+ _emergencyQueue.Enqueue(patient);
}
}
\ No newline at end of file