Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
union_of_two_arrays.cpp File Reference

Implementation for the Union of two sorted Arrays algorithm. More...

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
Include dependency graph for union_of_two_arrays.cpp:

Namespaces

namespace  operations_on_datastructures
 for std::vector
 
namespace  tests
 Testcases to check Union of Two Arrays.
 

Functions

void operations_on_datastructures::print (const std::vector< int32_t > &array)
 Prints the values of a vector sequentially, ending with a newline character.
 
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.
 
void tests::test1 ()
 A Test to check an simple case.
 
void tests::test2 ()
 A Test to check an empty vector.
 
void tests::test3 ()
 A Test to check an invalid shift value.
 
void tests::test4 ()
 A Test to check a very large input.
 
void tests::test5 ()
 A Test to check a shift of zero.
 
void tests::test6 ()
 A Test to check correct functionality with an array sorted using std::sort.
 
static void test ()
 Function to test the correctness of get_union() function.
 
int main ()
 main function
 

Detailed Description

Implementation for the Union of two sorted Arrays algorithm.

The Union of two arrays is the collection of all the unique elements in the first array, combined with all of the unique elements of a second array. This implementation uses ordered arrays, and an algorithm to correctly order them and return the result as a new array (vector).

See also
intersection_of_two_arrays.cpp
Author
Alvin

Function Documentation

◆ main()

int main ( void )

main function

Returns
0 on exit
217 {
218 test(); // run self-test implementations
219 return 0;
220}
static void test()
Function to test the correctness of get_union() function.
Definition union_of_two_arrays.cpp:204
Here is the call graph for this function:

◆ test()

static void test ( )
static

Function to test the correctness of get_union() function.

Returns
void
204 {
205 tests::test1();
206 tests::test2();
207 tests::test3();
208 tests::test4();
209 tests::test5();
210 tests::test6();
211}
void test1()
A Test to check an simple case.
Definition array_left_rotation.cpp:75
void test4()
A Test to check a very large input.
Definition array_left_rotation.cpp:120
void test3()
A Test to check an invalid shift value.
Definition array_left_rotation.cpp:105
void test6()
A Test to check correct functionality with an array sorted using std::sort.
Definition intersection_of_two_arrays.cpp:166
void test2()
A Test to check an empty vector.
Definition array_left_rotation.cpp:90
void test5()
A Test to check a shift of zero.
Definition array_left_rotation.cpp:143
Here is the call graph for this function: