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
- Simple linked list
- Simple hash table
- More complex hash table
- Binary search tree
- Graph adjacency matrix
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
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.
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.