Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C++ program Begin the implementation of a binary C++ persistent vector

ID: 3789783 • Letter: H

Question

Help with C++ program

Begin the implementation of a binary C++ persistent vector like that described here: http://hypirion.com/musings/understanding-persistent-vector-pt-1 and http://hypirion.com/musings/understanding-persistent-vector-pt-2.
That is, the tree should be a binary tree rather than the more "performant" 32-ary one described in part 2.
For this assignment, you must provide
1) a constructor that takes a constant reference to an std::vector and results in a new persistent vector with the same contents. You should copy the contents of the vector into the leaves of the trie.
2) The trie should be composed of std::shared_pointers so that when the persistent vector is destructed, the elements will be automatically destructed (so long as no other copies have been made)
3) A copy constructor that takes a constant reference to another persistent_vector and produces a copy that shares the other vector's trie.
4) An assignment operator that takes a constant reference to another persistent_vector and produces a copy that shares the other vector's trie.
5) a bracket operator that returns a constant reference to the indexed element.
Your submission should be a single C++ header file that provides the implementation of the persistent vector. Use the attached header file as a starting point.
When finished, running test-1.cpp should yield something like:
persistent_vector of 11 elements with height 3
node 0x7ff331d004a0 : 0x7ff331d00400 0x7ff331d00430
node 0x7ff331d00400 : 0x7ff331d002d0 0x7ff331d00330
node 0x7ff331d002d0 : 0x7ff331d00030 0x7ff331d00090
leaf 0x7ff331d00030 : 0 1
leaf 0x7ff331d00090 : 2 3
node 0x7ff331d00330 : 0x7ff331d00100 0x7ff331d000e0
leaf 0x7ff331d00100 : 4 5
leaf 0x7ff331d000e0 : 6 7
node 0x7ff331d00430 : 0x7ff331d00140 0x0
node 0x7ff331d00140 : 0x7ff331d001b0 0x7ff331d00280
leaf 0x7ff331d001b0 : 8 9
leaf 0x7ff331d00280 : 10
element at index 3 is 3

Explanation / Answer

// constructing vectors #include #include int main () { // constructors used in the same order as described above: std::vector first; // empty vector of ints std::vector second (4,100); // four ints with value 100 std::vector third (second.begin(),second.end()); // iterating through second std::vector fourth (third); // a copy of third // the iterator constructor can also be used to construct from arrays: int myints[] = {16,2,77,29}; std::vector fifth (myints, myints + sizeof(myints) / sizeof(int) ); std::cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote