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<time.h>
#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;i<plist->length;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;i<plist->length;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;i<list->length;i++)
if(list->elem[i]<list->elem[i-1])
{ temp=list->elem[i];
list->elem[i]=list->elem[i-1];
for(j=i-1;temp<list->elem[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(j<m&&(list->elem[j]<list->elem[j+1]))
j++;
if(!(rc<list->elem[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[0];
list->elem[0]=temp;
heapadjust(list,0,i-1);
}
}
void bubblesort(liststruct *list)
{ int i,j,temp;
for(j=0;j<list->length-1;j++)
for(i=1;i<list->length-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;i<list->length-1;i++)
{ min=i;
for(j=i;j<list->length;j++)
if(list->elem[j]<list->elem[min])
min=j;
if(i!=min)
{ temp=list->elem[i];
list->elem[i]=list->elem[min];
list->elem[min]=temp;
}
}
} 3 2376 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.
<snip>
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);
"ne********@gmail.com" wrote: My English is poor...
.... snip ... I have no idea about the error. Can you tell me? Thank you
#include<time.h> #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);
....
Regardless of your English, you could attempt to indent your code
properly and make it readable. As it is I will not even attempt to
read it. Others may. You also omitted to show us the "list-seq.h"
header file, nor the also presumed "list-seq.c" code file.
Reduce your code to a minimum compilable file that exhibits the
problem, publish that and describe the actual problem. Do not use
tabs, and do not let lines exceed about 65 chars.
--
"I don't know where bin Laden is. I have no idea and really
don't care. It's not that important." - G.W. Bush, 2002-03-13
"No, we've had no evidence that Saddam Hussein was involved
with September the 11th." - George Walker Bush 2003-09-17 ne********@gmail.com wrote: My English is poor...
May I have something else to say.
I find almost every Chinese have no confidence about their English,
though they have leart a lot at school. My English is poor but I've
never see one cannot understand what I have said, especially on
computer languages -- because the code you wrote is the best explain.
Don't worry about your English and ask in c.l.c often, here you can get
excellent answers easier. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mohamed Fysal |
last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun
ction .
The callback function declared in the .cpp file of the Regular DLL is as fol
lows:
typedef BOOL...
|
by: Mantorok Redgormor |
last post by:
I have ran into a problem where I have a struct
that has a member which contains a pointer
to function and is initialized to a function
in the initializer list. With my array of
structs of this...
|
by: Razzel |
last post by:
I created this as a test:
#include <time.h>
main(){
printf(X1: %s\n", putim());
printf(X2: %s\n", putim());
}
putim() {
time_t t;
time(&t);
return(ctime(&t));
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c...
| |
by: Marcelo |
last post by:
Hi everybody,
I don't understand why I am having a problem in this code.
The problem is that my pointer *phist in main method, it is declared.
Then I send the pointer to my method, and this...
|
by: Martin Jrgensen |
last post by:
Hi,
I'm relatively new with C-programming and even though I've read about
pointers and arrays many times, it's a topic that is a little confusing
to me - at least at this moment:
----
1)...
|
by: dice |
last post by:
Hi,
In order to use an external api call that requires a function pointer I
am currently creating static wrappers to call my objects functions.
I want to re-jig this so I only need 1 static...
|
by: venkatagmail |
last post by:
I have problem understanding pass by value and pass by reference and
want to how how they are or appear in the memory:
I had to get my basics right again. I create an array and try all
possible...
|
by: omerbutt |
last post by:
hi there i have downloaded a prototype tooltip from
http://www.nickstakenburg.com/projects/prototip/
the logic it uses is to call the script after creating the <div> for example i am using the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |