The designer of STL chose a wonderful yet simple common approach - "The separation of data and operation".
- The data is held and managed by the Container classes.
- The operations over the containers are defined and managed by the configurable algorithms.
In this project I'm re-implementation some of the standard C++ containers with the specific usage, such as vector, map, and stack, under the namespace "ft" instead of "std".
To use these container classes in your project, simply include the appropriate header file and use the "ft" namespace. For example:
#include "vector.h"
int main() {
ft::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
for (int i : v) {
std::cout << i << std::endl;
}
}
➤ std::vector -> ft::vector:
➤➤ It is implemented using a dynamic array, which is a contiguous
block of memory that can be accessed using pointers.
The vector class is a dynamic array that can grow and shrink in size.
➤ std::map -> ft::map :
➤➤ The best type of tree data structure to implement a map container
in C++ would be a self-balancing binary search tree (BST), such as
a [Red-Black tree] or [AVL tree].
These trees provide O(log n) time for search, insertion, and deletion operations,
and have a well-balanced structure that ensures O(log n) time for most operations,
even in the worst case scenario.
➤ std::stack -> ft::stack :
➤➤ The stack is implemented by using a LIFO (last-in first-out) data structure.
Elements are pushed/popped from the "back" of the specific container,
which is known as the top of the stack.
- ft_container testers.
- allocator Class.
- vector.
- ptrdiff_t.
- allocator construct.
- C++ vector max_size().
- size vs capacity of a vector.
- Intro to Iterator traits.
- The difference between the (allocator.destruct) and (allocator.deallocate) in allocator class
- overloading with the usage of enable_if
- how to use enable_if with overloads
- The C++ std::map Associative Container
- Class RedBlackTree java
- Visualizing Red-Black Trees
- what does (template) rebind<> do?
Useful Notes: Notes