All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jedi.example.QuickSort Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package jedi.example;

import jedi.tuple.Tuple2;

import java.util.Comparator;
import java.util.List;

import static jedi.functional.Coercions.list;
import static jedi.functional.Comparables.lessThan;
import static jedi.functional.FunctionalPrimitives.*;

public class QuickSort {

	public static  List sort(final List collection, final Comparator comparator) {
		if (collection.size() < 2) {
			return collection;
		}

		final T head = head(collection);
		Tuple2, List> partitioned = partition(tail(collection), lessThan(head, comparator));
		return append(sort(partitioned.a(), comparator), list(head), sort(partitioned.b(), comparator));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy