https://github.com/gibsjose/cpp-cheat-sheet/blob/master/Data%20Structures%20and%20Algorithms.md
Exercise 1:
- Create std::array with size: 10.
- Fill it with number 5.
- Assign to 4th element value 3.
- Create another array with the same size.
- Swap arrays.
- Print both – one array in one line.
Exercise 2:
- Create vector with following values { 1, 2, 4, 5, 6 }.
- Erase the first value.
- Add 5 at the end.
- Create 12 in the vector at the beginning (emplace).
- Print vector size and max_size.
- Print the vector.
- Clear the vector.
- Print size.
Exercise 3:
- Create an empty vector.
- Print size and capacity.
- Resize vector to size 10 and fill it with 5.
- Print size and capacity.
- Reserve space for 20 elements.
- Print size and capacity.
- Shrink to fit.
- Print size and capacity.
Exercise 4:
- Create empty list.
- Fill it with numbers from 1 to 1’000’000.
- Measure time of execution (time ./a.out in terminal)
- Print value of element with index 500’000
- Measure time of execution
- Replace list with vector
- Measure time of execution
Exercise 5:
- Create a map of integers to strings with content: {1 → ‘one’, 2 → ‘two’, 3 → ‘thr’, 4 → ‘four’, 5 → ‘five’}
- Add a new pair: 3 → ‘three’
- Erase element with key 5.
- Print how many values exist for all keys
- Find element with key 4 and print its key and value.
Exercise 6:
- Create std::forward_list with some data (integers) at least 7.
- Get two iterators with global functions begin(), end().
- Print size of the list
- Get an iterator to the 5th element and print its value.
- Print distance() from beginning to this iterator.
Exercise 7:
- Use std::bind to create a functor that multiplies given value by 5 (use std::multiplies).
- Print the result of this functor with 11 as an argument.
- Replace std::bind with a lambda function REMARK: in this task use std::function instead of auto.
Exercise 8:
- Create std::array of 6 doubles with the following elements: {5.0, 4.0, -1.4, 7.9, -8.22, 0.4}
- Sort elements of array using std::sort and provide a functor, that sorts by absolute values (std::abs)
- Change the functor object to the lambda function.
Exercise 9: Write function is_palindrome that will check if given std::string is a palindrome or not. Use std::mismatch().
Exercise 10:
- Use iterators to initialize std::vector with some values (some should occur more than once).
- Sort the container.
- Print the container’s content (using iterator + std::copy).
- Make the container unique.
- Print the container.
- Reverse the container.
- Print the container.
Exercise 11:
- Create empty std::deque for int values.
- Generate 14 values using std::back_inserter and std::generate_n with rand() but limited to 7 (use std::modulus).
- Sort values and print them.
- Leave only unique values in container and print them.
- Rotate them around middle element and print result.
Execrice 12.A (in groups): Cryptographic application. Requirements:
- Substitution ciphering (map letter -> cipher)
- Encryption and decryption
- Cipher is generated randomly
- Input data: cin and/or file
- Output data: cout and/or file
Execrice 12.B (in groups): Divisors Finder Requirements:
- Generate N random values (int numbers from 0 to M)
- Generate all prime numbers from 0 to M
- Create a map Prime -> Values, where Prime is a divisor of Value. (eg. 3 -> [6,9] where 6,9 are generated random numbers)
- Input data: N, M (from cin)