一道超级简单的排序题目
程序代码:
#include<stdio.h> #include<stdlib.h> #define YES 1 #define NO 0 void SWAP(int x,int y) {int t;t=x;x=y;y=t;} void ORDER2(int x,int y) {if(x>y) SWAP(x,y);} void ORDER3(int x,int y,int z) {ORDER2(x,y),ORDER2(x,z),ORDER2(y,z);} void quicksort(int *left,int *right); int pivot(int *left,int *right,int *pivot_pos); int *partition(int *left,int *right,int pivot); int main() { int i,a[1000],N; scanf("%d",&N); for(i=0;i<N;i++) { scanf("%d",&a[i]); } quicksort(a,a+N-1); for(i=0;i<N;i++) printf("%d\t",a[i]); return 0; } void quicksor(int *left,int *right) { int *p,pivot_p; if(pivot(left,right,&pivot_p)) { p=partition(left,right,pivot_p); quicksort(left,p-1); quicksort(p,right); } } int pivot(int *left,int *right,int *pivot_pos) { int a,b,c,*p; a=*left; b=*(left+(right-left)/2); c=*right; ORDER3(a,b,c); if(a<b) { *pivot_pos=b; return YES; } else if(b<c) { *pivot_pos=c; return YES; } else for(p=left+1;p<=right;p++) if(*p!=*left) { *pivot_pos=(*p<*left)?*left:*p; return YES; } return NO; } int *partition(int *left,int *right,int pivot) { while(left<=right) { while(*left<pivot) left++; while(*right>=pivot) right--; if(left<right) { SWAP(*left,*right); left++; right--; } } return left; }
运行一下,一个错误,是:
Linking...
试一试.obj : error LNK2001: unresolved external symbol "void __cdecl quicksort(int *,int *)" (?quicksort@@YAXPAH0@Z)
Debug/试一试.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
完全不知道为什么错了。