mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-06-15 13:04:18 -06:00
25 lines
1.8 KiB
Markdown
25 lines
1.8 KiB
Markdown
# Collection of Common Data Structs
|
|
The std library includes a number of useful data structures called collections
|
|
|
|
Collections can contain multiple values unlike built in array and tuples types these are all stored on the heap which means the amount of data does not need to be known at compile time and can grow or shrink as the program runs
|
|
|
|
each kind of collection has different capabilities and cost
|
|
choosing the right one is a skill that is developed over time
|
|
|
|
## Common Collections
|
|
- [*Vector*](Vector.md) - allows for storing a variable number of values next to each other
|
|
- [*String*](String.md) - a collection of characters
|
|
- [*Hash Map*](Hash Map.md) - allows you to associate a value with a specific key
|
|
- Its particular implementation is a more general version of a general data struct called a map
|
|
- {
|
|
- 1: data,
|
|
- 2: more_data,
|
|
- 3: this is a map
|
|
- }
|
|
|
|
|
|
# Summary
|
|
Here are some exercise that should be able to solve after reading through some of the common collections in the std library
|
|
- Given a list of integers, use a vector and return the median (when sorted, the value in the middle position) and mode (the value that occurs most often; a hash map will be helpful here) of the list.
|
|
- Convert strings to pig latin. The first consonant of each word is moved to the end of the word and ay is added, so first becomes irst-fay. Words that start with a vowel have hay added to the end instead (apple becomes apple-hay). Keep in mind the details about UTF-8 encoding!
|
|
- Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company; for example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all people in a department or all people in the company by department, sorted alphabetically. |