Defined a sorting algorithm as the flattening of a sorted tree made from input data.