Selects the smallest or largest element during each pass.