Implements cocktailSort