One approach:
* have collection of (label,value) pairs
* sort the collection according to the value, ascending http://www.cplusplus.com/reference/algorithm/sort/
* first and last are now smallest and largest
* for all other labels you can look up the previous and next element in the collection