DEV Community

Cover image for Programming in C++ (Part 10 Data Structures)
Mark Mahoney
Mark Mahoney

Posted on

Programming in C++ (Part 10 Data Structures)

This post describes how to build some common data structures: a hash table, a binary search tree, and a graph. I also describe how to use the STL unordered_map class.

Call to Action

Now that you have reviewed the guided code walk-throughs I ask that you write a program that includes a class which is equivalent of the vector called SafeArray. SafeArray has a method called at that returns the element at the specified position. A SafeArray maintains a pointer to an array on the heap. Use the pointer to make the array grow and shrink with calls to push_back and pop_back. The SafeArray will have a method called size that returns the number of items in it. Include a default constructor that sets the initial size of the underlying array to hold 10 elements. Include a destructor to delete the array when the SafeArray falls out of scope.

Comments and Feedback

You can find all of these code playbacks in my free 'book', An Animated Introduction to Programming in C++. I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter @markm208.

Discussion (0)