quick sort algorithm from Stanford Algorithms lecture