Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generic functions

Status
Not open for further replies.

isato

Programmer
Jan 26, 2008
1
SE
Hi I am trying to implement a generic version of bubblesort.

bubblesort(void *p, int lenght)
{...
.....
.....
if(p>p[i+1])//switch

........
.....

The compiler is giving me an error. at the same line as
if(p>p[i+1])

why?
 
Plenty of psychos here, but not many psychics. You gotta show your code AND the error message so we don't have to try to read your mind.

Copy and paste the code, too, so we see exactly what you've written.

Lee
 
Read O'Reilly's algorithms in C and K&R C before posting questions without detail.
 
p has been declared as void*. That means that p is void. There is no > operator defined for void, hence the error.

What you need to do is define a function which takes two void* parameters, casts them to the correct type, does the comparison and returns the correct result.

Also, the parameter should be a void** then you pass in two void*s to the function and all is bright and rosy.

Have a look at the template for quicksort and you'll get the general idea.
 
Sorry I meant prototype: not template.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top