Chapter 12 C and C++
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.
- Do it in place?
- 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++?
- What is a virtual table?
- Shallow vs Deep Copy: what is the difference between deep copy and shallow copy.
- Values or objects?
- Volatile: what is the significance of the keyword
volatilein C?
- In what situation may the value of the
volatilevariable 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
Nodedata structure recursively. ANodemay point to two otherNodes.
- 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
nblocks of memory, can the entire array be allocated at once?