Files
Main/Temporary/C++ Data Structures.md
2024-12-02 15:11:30 +01:00

57 lines
2.0 KiB
Markdown

---
title: C++ Data Structures
created_date: 2024-11-11
updated_date: 2024-11-11
aliases:
tags:
---
# C++ Data Structures
## Vectors
- stores sequence of data in variable length container (like an array, but variable in size)
- insertions other than at the end are slow, because elements must be shifted
- Applications:
- Paths and Waypoints and trajectories
- Vectors of vectors allow to store matrices
- dynamic resizing
- any element can be accessed --> random access
- access all element at once, filter, sort them, etc
## Stack and Queues
- storing data in specific order
### Stack
- LIFO: Last in first out
- meaning if i stack 1 then 2 then 3 and then I pop them I get 3 first, then 2 and finally 1
- 1,2,3 --> 3,2,1
- Applications
- Backtracking algorithms: if you hit a dead end and you need to go back to a previous node from where you can explore another path.
- Depth first search
- Undo/Redo functionality (last action must be undone first)
- store navigation history (web browsers)
- manage states (you could go back to a previous state)
### Queues
- FIFO: First in First Out
- 1,2,3 --> 1,2,3
- Applications:
- Buffers of sensors
- moving average implementation
- data streaming
## Sets
- collection of **unique** elements
- you cannot modify elements of a set
- ordered and unordered sets
- Applications
- UID management:
- keep track of objects in a scene (label each with a unique id) --> robotics navigation, etc.
- Store valid configuration sets for system. Invalid configurations can be detected
- Keep track of visited nodes/cells in grid. unordered cell --> very fast lookup if cell has already been visited
- Union, intersections and difference
- used in multi robot systems.
- Feature and Capabillity Tracking: Keep track of which sensors are online, which features are working
- Finite State Machines and Transitions: keep track of allowed states and prevent illegal ones
## Arrays
- fixed size
- useful for limited memory tasks
## Hash Map
- collection of unique elements as key-value pairs. Access them through `.first` and `.secondo`