zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Helper/LinkedListHelper.cs

28 lines
747 B
C#

using System;
using System.Collections.Generic;
namespace ET
{
public static class LinkedListHelper
{
public static void InsertToLinkedListAndSort<T>(LinkedList<T> list, T t, Func<T, T, bool> sortMatch)
{
if (list == null)
return;
LinkedListNode<T> node = null;
for (LinkedListNode<T>? item = list.First; item != null; item = item.Next)
{
if (sortMatch == null || sortMatch(t, item.Value))
{
node = item;
break;
}
}
if (node == null)
list.AddLast(t);
else
list.AddBefore(node, t);
}
}
}