Removed a bug in the AddParticipants method
And completed the GetResultList method
This commit is contained in:
parent
19eeb95db3
commit
90a33cdfde
2 changed files with 55 additions and 2 deletions
|
|
@ -8,6 +8,11 @@ public sealed class Marathon
|
|||
public readonly DateOnly Date;
|
||||
public int ParticipantCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for the Marathon class
|
||||
/// </summary>
|
||||
/// <param name="city">The city</param>
|
||||
/// <param name="date">The Date of the Marathon</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a participant from the list
|
||||
/// </summary>
|
||||
/// <param name="startNo">The start number of the participant to remove</param>
|
||||
/// <returns>true: if the operation succeeded; false: if it failed</returns>
|
||||
public bool RemoveParticipant(int startNo)
|
||||
{
|
||||
Node? nodeToRemove = GetNodeByStartNo(startNo);
|
||||
|
|
@ -86,11 +105,35 @@ public sealed class Marathon
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The list of participants in the marathon
|
||||
/// </summary>
|
||||
/// <returns>the array string of the list of participants</returns>
|
||||
public string[] GetResultList()
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string representation of the Marathon
|
||||
/// </summary>
|
||||
/// <returns>the string representation</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{City} marathon on {Date.ToString(Const.Culture)}";
|
||||
|
|
@ -186,6 +229,11 @@ public sealed class Marathon
|
|||
startingNode.Next = middleNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node by the index
|
||||
/// </summary>
|
||||
/// <param name="index">The index to return</param>
|
||||
/// <returns>the found node</returns>
|
||||
Node? GetNodeByIndex(int index)
|
||||
{
|
||||
if(index <= 0)
|
||||
|
|
@ -206,6 +254,11 @@ public sealed class Marathon
|
|||
return current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node by the start number
|
||||
/// </summary>
|
||||
/// <param name="startNo">The start number</param>
|
||||
/// <returns>the found node</returns>
|
||||
Node? GetNodeByStartNo(int startNo)
|
||||
{
|
||||
Node? current = _head;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue