[转] quicksort.c

#include <stdio.h> #include <time.h> #include <stdlib.h> typedef TYPE T; void quicksort(T* data, int N) { int i, j; T v, t; if( N <= 1 ) return; // Partition elements v = data[0]; i = 0; j = N; for(;;) { while(data[++i] < v && i < N) { } while(data[--j] > v) { } if( i >= j ) break; t = data[i]; data[i] = data[j]; data[j] = t; } t = data[i-1]; data[i-1] = data[0]; data[0] = t; quicksort(data, i-1); quicksort(data+i, N-i); }

posted on 2010-03-23 04:08  小橋流水  阅读(112)  评论(0编辑  收藏  举报

导航