DEV Community

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

Posted on • Edited 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 direct message.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay