06. Sorting/strand Sort.cpp
void strandSort(list<int> &ip, list<int> &op)
{
	// Base case : input is empty
	if (ip.empty())
		return;

	// Create a sorted sublist with
	// first item of input list as
	// first item of the sublist
	list<int> sublist;
	sublist.push_back(ip.front());
	ip.pop_front();
	
	// Traverse remaining items of ip list
	for (auto it = ip.begin(); it != ip.end(); ) {

		// If current item of input list
		// is greater than last added item
		// to sublist, move current item
		// to sublist as sorted order is
		// maintained.
		if (*it > sublist.back()) {
			sublist.push_back(*it);

			// erase() on list removes an
			// item and returns iterator to
			// next of removed item.
			it = ip.erase(it);
		}

		// Otherwise ignore current element
		else
			it++;
	}

	// Merge current sublist into output
	op.merge(sublist);

	// Recur for remaining items in
	// input and current items in op.
	strandSort(ip, op);
}
// A recursive function to implement Strand
// sort.
// ip is input list of items (unsorted).
// op is output list of items (sorted)
A recursive function to implement Strand
sort.
ip is input list of items (unsorted).
op is output list of items (sorted)
A recursive function to implement Strand sort . ip is input list of items ( unsorted ) . op is output list of items ( sorted )
void strandSort(list<int> &ip, list<int> &op)
{
	if (ip.empty())
		return;
	list<int> sublist;
	sublist.push_back(ip.front());
	ip.pop_front();
	for (auto it = ip.begin(); it != ip.end(); ) {
		if (*it > sublist.back()) {
			sublist.push_back(*it);
			it = ip.erase(it);
		}
		else
			it++;
	}
	op.merge(sublist);
	strandSort(ip, op);
}
void strandSort ( list < int > & ip , list < int > & op ) { if ( ip . empty ( ) ) return ; list < int > sublist ; sublist . push_back ( ip . front ( ) ) ; ip . pop_front ( ) ; for ( auto it = ip . begin ( ) ; it != ip . end ( ) ; ) { if ( * it > sublist . back ( ) ) { sublist . push_back ( * it ) ; it = ip . erase ( it ) ; } else it ++ ; } op . merge ( sublist ) ; strandSort ( ip , op ) ; }
A recursive function to implement Strand
sort.
A recursive function to implement Strand sort .
// Base case : input is empty // Create a sorted sublist with // first item of input list as // first item of the sublist // Traverse remaining items of ip list // If current item of input list // is greater than last added item // to sublist, move current item // to sublist as sorted order is // maintained. // erase() on list removes an // item and returns iterator to // next of removed item. // Otherwise ignore current element // Merge current sublist into output // Recur for remaining items in // input and current items in op.