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

# array-sort

state =
{
  ulong flag;
  ulong rq_greater_or_lesser;
};

cmp = ((ptr, ptr) ulong); 
swp = ((pptr -&w, pptr -&w) void);

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

  ...
}

void 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 */

void 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 */

void 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;
  }
}

# >> sort