Home | Projects | Notes > Problem Solving > EPI - 7.1. Interconvert Strings and Integers

EPI - 7.1. Interconvert Strings and Integers

 

Solutions in C++

Solution - IntToString()

Negative numbers are handled by recording the sign and negating the result.

Complexity Analysis:

Solution:

Inserting a single character rather than a string:

  • iterator insert(const_iterator p, char c);

Inserting n consecutive copies of character c:

  • string& insert(size_t pos, size_t n, char c);

Instead of prepending digits to the string, you could apend them and reverse the string at the end using the reverse() algorithm.

Solution - StringToInt()

Negative numbers are handled by recording the sign and negating the result.

Complexity Analysis:

Solution: