예제 #1
0
        public static ListNode <T> Sort <T>(ListNode <T> head)
        {
            ListNode <T>[] sorted   = LinkedListUtilities.Enumerate(head).OrderBy(o => o.Value).ToArray();
            ListNode <T>   sentinel = new ListNode <T>();
            ListNode <T>   tail     = sentinel;

            foreach (ListNode <T> current in sorted)
            {
                tail.Next        = current;
                current.Previous = tail;
                tail             = current;
            }

            sentinel.Next.Previous = null;
            return(sentinel.Next);
        }
예제 #2
0
 public static T[] ToArray <T>(ListNode <T> head)
 {
     return(LinkedListUtilities.Enumerate(head).Select(o => o.Value).ToArray());
 }
예제 #3
0
        public static void Append <T>(ListNode <T> a, ListNode <T> b)
        {
            ListNode <T> tail = LinkedListUtilities.Tail(a);

            tail.Next = b;
        }