Exercises
- Last K Lines: print the last K lines of an input file using C++.
- How to efficiently purge the oldest line from the array? Circular array.
- Reverse String: reverse a null-terminated string.
- Hash Table vs STL Map: compare and contrast a hash table and an STL map.
- How is a hash table implemented? Hashing and chaining to handle collisions.
- How is an STL map implemented? Binary search tree based on the keys.
- Virtual Functions: how do virtual functions work in C++?
- Shallow vs Deep Copy: what is the difference between deep copy and shallow copy.
- Volatile: what is the significance of the keyword
volatile in C?
- In what situation may the value of the
volatile variable be changed?
- Virtual Base Class: why does a destructor in base class need to be declared
virtual?
- When are virtual functions useful?
- Copy Node: copy a
Node data structure recursively. A Node may point to two other Nodes.
- How to copy the entire data structure? Graph traversal with a “visited” set.
- Smart Pointer: write a smart pointer class.
- How does smart pointers work?
- Malloc: write an aligned malloc and free function.
- How to manage dynamic memory?
- 2D Alloc: allocates a two-dimensional array
arr[n][m].
- Instead of common practice of allocating
n blocks of memory, can the entire array be allocated at once?