/* Shuffle sort a.k.a. "cocktail sort" */

state =
{
  ulong flag;
  ulong rq_greater_or_lesser;
};

cmp = ((ptr, ptr) byte); 
swp = ((pptr -&w, pptr -&w) .);

sort (ptr -&w array[], int length, cmp compare, SORT_* order_by = SORT_ASC)
{
  swap (pptr -&w first, pptr -&w second)
  {
    *first = *second = *first;
  }

  ...
}

sort _ (ptr -&w array[], p_state -&w st, int length, cmp compare, swp swap)
{
  ...
}

/* Walking up the array.
   This function will move the greatest element 
   to the right bound of the array */

left_to_right sort (ptr -&w array[], p_state -&w st, int begin, int end, cmp compare, swp swap)
{
  ...
}

/* Walking down the array.
   This function will move the lowest element 
   to the left bound of the array */

right_to_left sort (ptr -&w array[], p_state -&w st, int begin, int end, cmp compare, swp swap)
{
  ...
}

/* Swapping two neighbors */

swap_two left_to_right, right_to_left (ptr -&w array[], p_state -&w st, int first, cmp compare, swp swap)
{
  second = first + 1;

  if (compare (array[first], array[second]) == st->rq_greater_or_lesser)
  {
    swap (&array[first], &array[second]); st->flag = 1;
  }
}

