#include #include #include #include class Jump_List { private: struct Node; public: Jump_List() = default; int& at(int index) { Node* current { first }; if (index >= count) { throw std::out_of_range { "Jump_List out of range" }; } if (index % 2 == 1) { current = current->next; --index; } while (index > 0) { current = current->jump; index -= 2; } return current->value; } void pop_front() { Node* tmp { first }; first = first->next; delete tmp; --count; } int size() const { return count; } void print(std::ostream& os) const { Node* current { first }; os << "size " << size() << ": "; while (current != nullptr) { os << current->value << " "; current = current->next; } os << std::endl; } private: struct Node { int value { }; Node* jump { }; Node* next { }; }; Node* first { }; int count { }; }; int main() { Jump_List l1 { }; for (int i { 9 }; i >= 0; --i) { l1.push_front(i); } Jump_List l2 { l1 }; for (int i { 0 }; i < 4; ++i) { l1.pop_front(); } l1.print(std::cout); l2.print(std::cout); // TODO: Insert tests for move and copy-semantics. }