using System; using System.Collections.Generic; namespace ET { public static class LinkedListHelper { public static void InsertToLinkedListAndSort(LinkedList list, T t, Func sortMatch) { if (list == null) return; LinkedListNode node = null; for (LinkedListNode? 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); } } }