Re: Median of array values
Re: Median of array values
Thanks Chris F for the link.
Is it possible to do it using plain ANSI C ?
Re: Median of array values
I've never used this before, but here is a C library function.
http://www.cplusplus.com/reference/c...cstdlib/qsort/
Re: Median of array values
Thanks again Chris F.
any idea where can i get code for qsort()?
Another point is that the values are not constant in the array, instead the array is being filled up constatly by newer values which are bering received from the serial port. Is it possible to do the sorting operation of every new incoming value dynamically, something like serial-arithmatic?
Re: Median of array values
Quote:
Originally Posted by
naim1
Thanks again Chris F.
any idea where can i get code for qsort()?
The qsort() is a standard library function. Any code for it would come with your compiler (if your compiler offers source code to the library routines).
Regards,
Paul McKenzie
Re: Median of array values
If you wanted a better average case performance than sorting and then picking the middle, you could use the nth element algorithm of picking a pivot, partitioning as in quick sort, and then only performing the recursion on the partition that contains the middle element.
Quote:
Originally Posted by naim1
Another point is that the values are not constant in the array, instead the array is being filled up constatly by newer values which are bering received from the serial port. Is it possible to do the sorting operation of every new incoming value dynamically, something like serial-arithmatic?
As in the new values replace existing ones in the array?