#include <stdio.h>

#define ARRAYLEN 10

void bubbleSort(int *a, const int l, const int r);

// allgemeine Array-Werkzeuge
void copyArray(int * source, int * dest, const int len);
void printArray(const int * a, const int len);
void swap(int * a, int * b);

void bubbleSort(int *a, const int l, const int r)
{
  int i, k;

  for (k=r; k > l; --k)
  {
    for (i=l; i < k; ++i)
    {
      if (a[i] > a[i+1]) swap(&a[i], &a[i+1]);
    }
  }
}

void copyArray(int * source, int * dest, const int len)
{
  int i;
  for (i=0; i<len; ++i)
  {
    dest[i] = source[i];
  }
}

void printArray(const int * a, const int len)
{
  int i;
  for (i=0; i<len; ++i)
  {
    printf(" %d", a[i]);
  }
  printf("\n");
}

void swap(int * a, int * b)
{
  if (a==b) return;
  *a ^= *b;
  *b ^= *a;
  *a ^= *b;
}

int main(void) {
  int unordnung[ARRAYLEN] = { 4, 7, 2, 5, 1, 9, 3, 8, 6, 0 };

  printArray(unordnung, ARRAYLEN);
  bubbleSort(unordnung, 0, ARRAYLEN-1);
  printArray(unordnung, ARRAYLEN);

  return 0;
}

