The following algorithm can sort three variables x, y and z of type K which are comparable using operator<
x
y
z
K
operator<
If you don't do it in place, you can perform it without any swaps.