From 90a33cdfde2d9556e0367ea377e8c1a4d9d36127 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:37:02 +0100 Subject: [PATCH] Removed a bug in the AddParticipants method And completed the GetResultList method --- Marathons/Marathon.cs | 55 +++++++++++++++++++++++++++++++++++++++- Marathons/Participant.cs | 2 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Marathons/Marathon.cs b/Marathons/Marathon.cs index 773da47..aa89773 100644 --- a/Marathons/Marathon.cs +++ b/Marathons/Marathon.cs @@ -8,6 +8,11 @@ public sealed class Marathon public readonly DateOnly Date; public int ParticipantCount { get; private set; } + /// + /// The constructor for the Marathon class + /// + /// The city + /// The Date of the Marathon public Marathon(string city, DateOnly date) { City = city; @@ -36,6 +41,8 @@ public sealed class Marathon _tail = middleNode; return; } + + // Checking all the possibilities if(leftNode == null && rightNode != null) { _head = middleNode; @@ -53,9 +60,21 @@ public sealed class Marathon { return; } + + if (insertIndex == 0) + { + MoveNode(middleNode, rightNode); + _head = middleNode; + return; + } MoveNode(leftNode, rightNode, middleNode); } + /// + /// Removes a participant from the list + /// + /// The start number of the participant to remove + /// true: if the operation succeeded; false: if it failed public bool RemoveParticipant(int startNo) { Node? nodeToRemove = GetNodeByStartNo(startNo); @@ -86,11 +105,35 @@ public sealed class Marathon return true; } + /// + /// The list of participants in the marathon + /// + /// the array string of the list of participants public string[] GetResultList() { - return Array.Empty(); + if(ParticipantCount == 0) + { + return []; + } + + string[] result = new string[ParticipantCount]; + for (int i = 0; i < ParticipantCount; i++) + { + Node? current = GetNodeByIndex(i); + if (current == null) + { + return []; + } + result[i] = $"#{i+1:00} {current.Data}"; + } + + return result; } + /// + /// Returns the string representation of the Marathon + /// + /// the string representation public override string ToString() { return $"{City} marathon on {Date.ToString(Const.Culture)}"; @@ -186,6 +229,11 @@ public sealed class Marathon startingNode.Next = middleNode; } + /// + /// Gets the node by the index + /// + /// The index to return + /// the found node Node? GetNodeByIndex(int index) { if(index <= 0) @@ -206,6 +254,11 @@ public sealed class Marathon return current; } + /// + /// Gets the node by the start number + /// + /// The start number + /// the found node Node? GetNodeByStartNo(int startNo) { Node? current = _head; diff --git a/Marathons/Participant.cs b/Marathons/Participant.cs index 2cf30c8..72866ff 100644 --- a/Marathons/Participant.cs +++ b/Marathons/Participant.cs @@ -24,7 +24,7 @@ public sealed class Participant // Check if the completion time is the same if(CompletionTime == participant.CompletionTime) { - return StartNo > participant.StartNo ? -1 : 1; + return StartNo < participant.StartNo ? -1 : 1; } return CompletionTime < participant.CompletionTime ? -1 : 1;