Stack sorting

Not very efficient, but given the constraints, not terrible IMO.