|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
for std::vector More...
Functions | |
| void | print (const std::vector< int32_t > &array) |
| Prints the values of a vector sequentially, ending with a newline character. More... | |
| std::vector< int32_t > | get_union (const std::vector< int32_t > &first, const std::vector< int32_t > &second) |
| Gets the union of two sorted arrays, and returns them in a vector. More... | |
for std::vector
For std::vector.
for assert for IO Operations
Operations on data structures
For assert For IO operations For std::queue
Operations on Data Structures
for std::count for assert for tolower for string operations for IO Operations
Operations on data structures
for std::sort for assert for IO operations
Operations on Data Structures
| std::vector< int32_t > operations_on_datastructures::get_union | ( | const std::vector< int32_t > & | first, |
| const std::vector< int32_t > & | second | ||
| ) |
Gets the union of two sorted arrays, and returns them in a vector.
An algorithm is used that compares the elements of the two vectors, appending the one that has a lower value, and incrementing the index for that array. If one of the arrays reaches its end, all the elements of the other are appended to the resultant vector.
| first | A std::vector of sorted integer values |
| second | A std::vector of sorted integer values |
< Vector to hold the union
< Index for the first array
< Index for the second array
< Length of first array
< Length of second array
< Integer to store value of the next element
< Append from first array
< Increment index of second array
< Append from second array
< Increment index of second array
< Element is the same in both
< Increment index of first array
< Increment index of second array too
< Add the element if it is unique
< Add remaining elements
< Add the element if it is unique
< Add remaining elements
< Add the element if it is unique
| void operations_on_datastructures::print | ( | const std::vector< int32_t > & | array | ) |
Prints the values of a vector sequentially, ending with a newline character.
| array | Reference to the array to be printed |
Print each value in the array
Print newline