implements the quick sort