In this section, we will implement simple compress and decompress functions for strings:
- We include some STL libraries first, then we declare that we use the std namespace:
#include <iostream> #include <string> #include <algorithm> #include <sstream> #include <tuple> using namespace std;
- For our cheap compression algorithm, we try to find chunks of text containing ranges of the same characters, and we compress those individually. Whenever we start at one string position, we want to find the first position where it contains a different character. We use std::find to find the first character in the range, which is different than the character at the current position. Afterward, we return a tuple containing an iterator ...