#include "utils1.h" apstring IntToString(int n) // postcondition: returns stringized form of n { if (n == 0) { return "0"; // special case for 0 } int k; apstring reverse = ""; // will be correct, but in reverse apstring val = ""; // the string returned if (n < 0) // start with "-" if n < 0 { val = "-"; n = -n; } while (n > 0) // get each digit, catenate in reverse { reverse += char('0' + n % 10); n /= 10; } // now build the string to return by "unreversing" for (k = reverse.length() - 1; k >= 0; k--) { val += reverse[k]; } return val; }