/// <summary> /// Time complexity: O(nlog(n)). /// </summary> public static IEnumerable <T> Sort(IEnumerable <T> enumerable, SortDirection sortDirection = SortDirection.Ascending) { //create BST var tree = new RedBlackTree <T>(); foreach (var item in enumerable) { tree.Insert(item); } return(sortDirection == SortDirection.Ascending ? tree.AsEnumerable() : tree.AsEnumerableDesc()); }