Description | Selection algorithms |
Header file | LSelect.h |
Author | Irene Finocchi, Francesco Iovine |
Created | Feb 7, 2005 |
Last updated | Nov 23, 2005 |
Constants |
|
LSelect_ID LSelect_BAD_SELECT |
Functions |
|
void LSelect_Rand (void* inItems, ui4 inItemsCount, LType_TType inItemType, ui4 inSelect); void LSelect_Determ (void* inItems, ui4 inItemsCount, LType_TType inItemType, ui4 inSelect); |
Function | Arguments | Description | Returns | Throws |
Rand | void* inItems | Works on inItemsCount items with
type descriptor inItemType contained in the array pointed to by
inItems. Moves the inSelect-th item to the inSelect-th position, using the classical quickSelect randomized algorithm. |
- | BAD_SELECT, if inSelect is out of range. |
ui4 inItemsCount | ||||
LType_TType inItemType | ||||
ui4 inSelect | ||||
Determ | void* inItems | Works on inItemsCount items with
type descriptor inItemType contained in the array pointed to by
inItems. Moves the inSelect-th item to the inSelect-th position, using the classical deterministic algorithm by Blum, Floyd, Pratt, Rivest and Tarjan. |
- | BAD_SELECT, if inSelect is out of range. |
ui4 inItemsCount | ||||
LType_TType inItemType | ||||
ui4 inSelect |
#include "LSelect.h" #include "LSystem.h" int main(){ ui4 i, k = 5, theItems[11] = { 34, 12, 6, 9, 33, 11, 4, 3, 11, 23, 26 }; /* print array */ for (i = 0; i < 11; ++i) LSystem_Print("%lu ", theItems[i]); LSystem_Print("\n"); /* select k-th item */ LSelect_Rand(theItems, 11, LType_UI4, k); /* print k-th item */ LSystem_Print("The %lu-th item is %lu \n", k, theItems[k-1]); return 0; }