Shaker/Cocktail sort implementation