C++ math logic

How to do a simple math logic as examples below?

Use the following
- is the largest
- is the smallest
- is between

Example 1:
A: 46
B: 58
C:100
D: 36

A is between D and B.
B is between A and C.
C is the largest.
D is the smallest.



Example 2:
A: 25
B: -10
C: 30
D: 15

A is between C and D.
B is the smallest
C is the largest.
D is between A and B.
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
Topic archived. No new replies allowed.