AddParticipants works perfectly, which leads to the Remove function to work perfectly as well
This commit is contained in:
parent
3c848945aa
commit
19eeb95db3
2 changed files with 21 additions and 4 deletions
|
|
@ -30,12 +30,29 @@ public sealed class Marathon
|
||||||
Node middleNode = new Node(participant);
|
Node middleNode = new Node(participant);
|
||||||
Node? leftNode = GetNodeByIndex(insertIndex - 1);
|
Node? leftNode = GetNodeByIndex(insertIndex - 1);
|
||||||
Node? rightNode = GetNodeByIndex(insertIndex);
|
Node? rightNode = GetNodeByIndex(insertIndex);
|
||||||
if (leftNode == null || rightNode == null)
|
if (leftNode == null && rightNode == null)
|
||||||
{
|
{
|
||||||
_head = middleNode;
|
_head = middleNode;
|
||||||
_tail = middleNode;
|
_tail = middleNode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(leftNode == null && rightNode != null)
|
||||||
|
{
|
||||||
|
_head = middleNode;
|
||||||
|
MoveNode(middleNode, rightNode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(rightNode == null && leftNode != null)
|
||||||
|
{
|
||||||
|
_tail = middleNode;
|
||||||
|
MoveNode(leftNode, middleNode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rightNode == null || leftNode == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
MoveNode(leftNode, rightNode, middleNode);
|
MoveNode(leftNode, rightNode, middleNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,14 +117,14 @@ public sealed class Marathon
|
||||||
//check if the participant is the first or last
|
//check if the participant is the first or last
|
||||||
int result = _head.Data?.CompareTo(participant) ?? 0;
|
int result = _head.Data?.CompareTo(participant) ?? 0;
|
||||||
// If the participant is the first or can be placed before the first
|
// If the participant is the first or can be placed before the first
|
||||||
if (result <= 0)
|
if (result >= 0)
|
||||||
{
|
{
|
||||||
exactPosFound = result == 0;
|
exactPosFound = result == 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// If the participant is the last or can be placed after the last
|
// If the participant is the last or can be placed after the last
|
||||||
result = _tail.Data?.CompareTo(participant) ?? 0;
|
result = _tail.Data?.CompareTo(participant) ?? 0;
|
||||||
if (result >= 0)
|
if (result <= 0)
|
||||||
{
|
{
|
||||||
exactPosFound = result == 0;
|
exactPosFound = result == 0;
|
||||||
return ParticipantCount;
|
return ParticipantCount;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public sealed class Participant
|
||||||
// Check if the completion time is the same
|
// Check if the completion time is the same
|
||||||
if(CompletionTime == participant.CompletionTime)
|
if(CompletionTime == participant.CompletionTime)
|
||||||
{
|
{
|
||||||
return StartNo < participant.StartNo ? -1 : 1;
|
return StartNo > participant.StartNo ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletionTime < participant.CompletionTime ? -1 : 1;
|
return CompletionTime < participant.CompletionTime ? -1 : 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue