37if (lst.size() < 2) { // Returns list if empty or contains only one element
38return lst; // Returns list
39 }
40 std::list<T> result; // Define new "result" named list instance.
41 std::list<T> sorted; // Define new "sorted" named list instance.
42while(!lst.empty()) /* if lst is not empty */ {
43 sorted.push_back(lst.front()); // Adds the first element of "lst" list to the bottom of the "sorted" list.
44 lst.pop_front(); // Remove first element of "lst" list.
45for (auto it = lst.begin(); it != lst.end(); ) { // Return the loop as long as the current iterator is not equal to the last literator of the "lst" list.
46if (sorted.back() <= *it) { // If the last reference of the "sorted" list is less than or equal to the current iterator reference.
47 sorted.push_back(*it); // Adds the iterator retrieved in the loop under the "sorted" list.
48 it = lst.erase(it); // Deletes the element with the current iterator and assigns the deleted element to the iterator.
49 } else {
50 it++; // Next iterator.
51 }
52 }
53 result.merge(sorted); // Merge "result" list with "sorted" list.