r/learncpp • • Aug 07 '20

I implemented some Data Structures in C++

Not sure if this is the place for posting code, if it is not, I apologize.

I implemented some data structures in C++. I am somewhat new to C++ and started this project originally to get used to std::unique_ptr via a LinkedList implementation and then decided to add a few more data structures.

Note that I have yet to fix the postorder Traversal for the binary search tree.

I think that a lot of the iterators I wrote may be bad practice, which is why I would really appreciate some feedback / suggestions for this project.

https://github.com/PetrifiedPanda/DataStructures

7 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/PetrifiedPanda Aug 07 '20

Thank you very much for the feedback, I already changed the smaller issues, such as not passing by reference and not utilizing the vector's copy constructor in the heap implementation, and added the noexcept specifier to the move constructor.

I'll think about using templates instead of std::function<> in the heap (or maybe making an alternate version where you cannot change the comparator)

I'll see what I'll do about LinkedLists, because I did not want to use the name size() because that may make someone think that this operation is O(1).

2

u/MysticTheMeeM Aug 07 '20

Alternatively, you can mask computeSize with a using declaration. This way you cannot directly call computeSize from a SizeLinkedList.

2

u/PetrifiedPanda Aug 07 '20

I did that now as well, thank you for the help!