#include <stdio.h> 
#include <stdlib.h> 
#include <sys/times.h> 

#define DIM 1000000

          main() 
          { 
                  struct tms buffer; 
                  int feld[DIM]; 
                  int feld_kopie[DIM]; 

                  int i; 
                  for (i=0;i<DIM;i++) 
                          { 
				if (i%2)
				  feld[i] = feld_kopie[i] = rand(); 
				else
				  feld[i] = feld_kopie[i] = 7; 
                          } 
                  times(&buffer); 
                  printf("Zeit vor dem Sortieren: %d\n",buffer.tms_utime); 
                  my_qsort_000000(feld, DIM ); 
                  times(&buffer); 
                  printf("Zeit vor dem UNIX Sortieren: %d\n",buffer.tms_utime); 
                  my_qsort_111111(feld_kopie, DIM ); 
                  times(&buffer); 
                  printf("Zeit nach dem UNIX Sortieren: %d\n",buffer.tms_utime); 

                  if (memcmp(feld,feld_kopie, DIM * sizeof(int) ) != 0) 
		    printf("Wir haben Probleme\n"); 
          } 

          int my_comp(const void  *a, const void  *b) 
          { 
                  return *(int*)a - *(int*)b; 
          } 

my_qsort_000000(int *feld, int feld_laenge) 
{
	qs(feld,0,feld_laenge-1);

}
my_qsort_111111(int *feld, int feld_laenge)
{
  qsort(feld,feld_laenge, sizeof(int), my_comp);
}  

qs(int a[],int l,int r)
{
int i,j,h,v;
if (r>l) 
	{
	i = l; j = r; v=a[l];
	do {
		do { i++; } while ((i<=r) && (a[i]<v));
		do { j--; } while ((j>=l) && (a[j]>v));

		if (j<i) break;
		h = a[i];a[i]=a[j];a[j]=h;
	} while (1);
	h = a[l];a[l]=a[j];a[j]=h;
	qs(a,l,j-1);
	qs(a,i,r);
	}
}