28 lines
747 B
C#
Executable File
28 lines
747 B
C#
Executable File
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);
|
|
}
|
|
}
|
|
}
|