446,234 Members | 1,938 Online Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

 P: n/a My English is poor... There are some sort algorithms which sort a sequencial list. The sequencial list was defined in "list-seq.h". sort_and_time() accepts one of these sort functions. It uses the sort function to sort the list and compute the time consumed by the sort function. I wrote the program as below. When sort_and_time() is called in main(), there are some errors:(in VC++6) D:\ds\funp.c(31) : error C2095: 'sort_and_time' : actual parameter has type 'void' : parameter 1 D:\ds\funp.c(31) : error C2198: 'sort_and_time' : too few actual parameters I have no idea about the error. Can you tell me? Thank you #include #include"list-seq.h" void insertsort(liststruct *list); void heapsort(liststruct *plist); void heapadjust(liststruct *plist,int s,int m); void bubblesort(liststruct *list); void selsort(liststruct *list); void sort_and_time(void (*sort)(liststruct *)); liststruct list,temp,*plist,*templist; time_t first,second; int i,x,way,j,k; int main() { plist=&list; templist=&temp; initial(templist); initial(plist); i=1; printf("è¾å¥æ°æ®ï¼ä»¥9999ç»æï¼\n"); scanf("%d",&x); while(x!=9999) { insert(plist,i,x); insert(templist,i,x); i++; scanf("%d",&x); } for(i=0;ilength;i++) printf("%d\n",plist->elem[i]); sort_and_time((*insertsort)(plist)); sort_and_time((*bubblesort)(plist)); sort_and_time((*heapsort)(plist)); sort_and_time((*selsort)(plist)); } void sort_and_time(void (*sort)(liststruct *)) { first=clock(); for(k=0;k<100000;k++) (*sort)(plist); second=clock(); printf("after sort:\n"); for(i=0;ilength;i++) printf("%d\t",plist->elem[i]); printf("\næç¨æ¶é´ï¼%lf\n",(double)(second-first)/CLOCKS_PER_SEC); initial(plist); for(i=1;i<=templist->length;i++) insert(plist,i,templist->elem[i-1]); } void insertsort(liststruct *list) { int i,j,temp; for(i=1;ilength;i++) if(list->elem[i]elem[i-1]) { temp=list->elem[i]; list->elem[i]=list->elem[i-1]; for(j=i-1;tempelem[j];--j) list->elem[j+1]=list->elem[j]; list->elem[j+1]=temp; } } void heapadjust(liststruct *list,int s,int m) { int j,rc; rc=list->elem[s]; for(j=2*s;j<=m;j*=2) { if(jelem[j]elem[j+1])) j++; if(!(rcelem[j])) break; list->elem[s]=list->elem[j]; s=j; } list->elem[s]=rc; } void heapsort(liststruct *list) { int i,temp; for(i=(list->length-1)/2;i>=0;i--) heapadjust(list,i,list->length-1); for(i=list->length-1;i>=1;i--) { temp=list->elem[i]; list->elem[i]=list->elem; list->elem=temp; heapadjust(list,0,i-1); } } void bubblesort(liststruct *list) { int i,j,temp; for(j=0;jlength-1;j++) for(i=1;ilength-1;i++) if(list->elem[i]>list->elem[i+1]) { temp=list->elem[i]; list->elem[i]=list->elem[i+1]; list->elem[i+1]=temp; } } void selsort(liststruct *list) { int i,j,temp,min; for(i=0;ilength-1;i++) { min=i; for(j=i;jlength;j++) if(list->elem[j]elem[min]) min=j; if(i!=min) { temp=list->elem[i]; list->elem[i]=list->elem[min]; list->elem[min]=temp; } } } Jun 19 '06 #1
3 Replies

 P: n/a ne********@gmail.com schreef: My English is poor... Never mind. It's good enough for me to understand. D:\ds\funp.c(31) : error C2095: 'sort_and_time' : actual parameter has type 'void' : parameter 1 D:\ds\funp.c(31) : error C2198: 'sort_and_time' : too few actual parameters Hmmm... something's wrong. I have no idea about the error. Can you tell me? Thank you Yes. void sort_and_time(void (*sort)(liststruct *)); The only parameter you define here is a pointer to a function. Nothing wron there. sort_and_time((*insertsort)(plist)); But this is. You are not trying to pass a pointer to a function, here, but the _result_ of a function call, which does not return anything (it's of type 'void'). sort_and_time((*bubblesort)(plist)); sort_and_time((*heapsort)(plist)); sort_and_time((*selsort)(plist)); and you do it three times more. Change the decl to void sort_and_time(void (*sort)(liststruct *), liststruct *); and the calls to sort_and_time(insertsort, plist); sort_and_time(bubblesort, plist); sort_and_time(heapsort, plist); sort_and_time(selsort, plist); Jun 19 '06 #2 