If i have 8-bit values saved in an array of 127 bytes, how would i calculate the Median of this array. Median of a set of values would be the central value of the set when its values are arranged in ascending order.
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?
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).
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.
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?
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Bookmarks