#include <stdio.h>
#include <string.h>

template <class T>
inline void swap(T &x, T &y)
{
    T tmp = x;
    x = y;
    y = tmp;
}

template <class T>
bool sort_less(T a, T b)
{
    return a < b;
}

template <>
bool sort_less<const char *>(const char *a, const char *b)
{
    return strcmp(a, b) < 0;
}

template <class T>
void sort(T *array, int len)
{
    for (int start = 0; ; start++) {
        bool done = true;
        for (int i = len - 2; i >= start; i--)
            if (sort_less(array[i+1], array[i])) {
                swap(array[i], array[i+1]);
                done = false;
            }
        if (done)
            break;
    }
}

int main()
{
    int a[] = { 5, 2, 8, 1 };
    int len_a = sizeof(a) / sizeof(*a);
    double d[] = { 2.5, -1.0, 0.5 };
    int len_d = sizeof(d) / sizeof(*d);
    const char *s[] = {"hello", "there", "how", "are", "you"};
    int len_s = sizeof(s) / sizeof(*s);

    sort(a, len_a);
    sort(d, len_d);
    sort(s, len_s);

    int i;
    for (i = 0; i < len_a; i++)
        printf("%d ", a[i]);
    printf("\n");

    for (i = 0; i < len_d; i++)
        printf("%g ", d[i]);
    printf("\n");

    for (i = 0; i < len_s; i++)
        printf("%s ", s[i]);
    printf("\n");

    return 0;
}
