#include #include #include #include using namespace std; class Rose; class Rose { public: Rose() : sublist(nullptr), next(nullptr) { contents.reserve(1000); } void add_contents(const uint8_t character) { if (! this->sublist) { this->contents.push_back(character); return; } if (! this->next) { this->contents.shrink_to_fit(); // compact heap as this is hopefully the 'freshest' object on the heap this->next = new Rose(); } this->next->add_contents(character); } Rose * make_sublist() { this->contents.shrink_to_fit(); // compact heap as this is hopefully the 'freshest' object on the heap this->sublist = new Rose(); return this->sublist; } void print(const bool is_first = true) { if (is_first) cout << "["; for (auto character : this->contents) { cout << character << ","; } if (this->sublist) this->sublist->print(); if (this->next) this->next->print(false); else cout << "]"; } private: Rose * sublist; Rose * next; vector contents; }; int main() { Rose rr; Rose* r=&rr; for (unsigned long i=1;i<40100100; i++) { if ((i%1000)!=0) { r->add_contents(static_cast(i % 256)); } else { Rose* l = r->make_sublist(); r=l; } } // rr.print(); //cout << "Hello, World!"; //cin.get(); return 0; }