#what are some data structures in c++ and what are they good for
19 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Python uses all of the same datastructures but the implementations are hidden away from you
you can use std::vector or std::unordered_map the same as you would use lists and dictionaries in python
The basic ones you should have a thorough understanding of are:
- dynamic arrays (std::vector, nearly universally applicable)
- linked lists (for fast insertion and deletion from the beginning or middle of a list)
- trees (good for lots of things, often searching for things)
- hashmaps (dictionaries, these are what python uses internally for dictionaries)
there are lots of other ones but you won't encounter them as often
stacks and queues are just linked lists with restricted subsets for operations, although you can also impelement them as dynamic arrays if you're feeling fancy
tysm is there any websites to practice c++ for beginners
learncpp.com is quality
I'll point out: Data structures are language agnostic. Most of them can be written in any language you desire. C++ provides a handful of them out of the box, as pudy mentioned
I'd argue the important ones to know are:
- Dynamic Arrays (std::vector)
- Stacks, Queues, and Deques (std::stack, std::queue, std::deque)
- Dictionaries (std::map, std::unordered_map, std::flat_map)
- Sets (std::set, std::unordered_set, std::flat_set)
Trees are used to implement std::set and std::map
Graphs are not in the standard library
From C++'s flexibility, you can implement your own data structures yourself instead of using the ones from C++ (things in std) and easily implement others that the standard doesn't provide at all, like DAGs and b-trees.
isn't a graph library proposed in c++26 or was that accepted
no that was linalg
c++29?
P3126?
It's still in various working groups, I think
I doubt it makes it to C++26, maybe C++29
@tribal fiber Has your question been resolved? If so, type !solved :)
!solved