写的一个快速排序,但一直提示函数多处定义,请指教
qsort.c
#define MAXSIZE 10
typedef struct
{
int r[MAXSIZE];
int length;
}Sqlist;
void Swap(Sqlist *L,int i,int j)
{
int temp =L->r[i];
L->r[i] =L->r[j];
L->r[j] =temp;
}
int Part(Sqlist *L,int low,int high)
{
int pivotkey;
pivotkey=L->r[low];
while(low < high)
{
while(low < high && pivotkey <= L->r[high])
high--;
Swap(L,low,high);
while(low < high && pivotkey >=L->r[low])
low++;
Swap(L,low,high);
}
return low;
}
void Qsort(Sqlist *L,int low,int high)
{
int pivot;
if(low < high)
{
pivot=Part(L,low,high);
Qsort(L,low,pivot-1);
Qsort(L,pivot+1,high);
}
}
void QuickSort(Sqlist *L)
{
QSort(L,0,L->length);
}
#include <stdio.h>
#include <stdlib.h>
#include "qsort.c"
int main()
{
int i;
int d[10]={50,30,21,44,65,52,78,42,78,90};
Sqlist *L=(Sqlist *)malloc(sizeof(Sqlist));
L->length=10;
for(i=0;i <10;i++)
{
L->r[i]=d[i];
}
QuickSort(L);
for(i=0;i <10;i++)
printf("%d\t",L->r[i]);
return 0;
}