Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
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 Reversal of Binary Tree.
 

Functions

void operations_on_datastructures::print (const std::vector< int32_t > &array)
 Prints the values of a vector sequentially, ending with a newline character. More...
 
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. More...
 
void tests::test1 ()
 < Use the BinaryTree More...
 
void tests::test2 ()
 A Test to check an edge case (NULL root element) More...
 
void tests::test3 ()
 A Test to check correct reversal of a Binary Tree. More...
 
void tests::test4 ()
 A Test to check correct functionality with duplicate values. More...
 
void tests::test5 ()
 A Test to check correct functionality with a harder test case. More...
 
void tests::test6 ()
 A Test to check correct functionality with an array sorted using std::sort. More...
 
static void test ()
 Function to test the correctness of get_union() function. More...
 
int main ()
 main function More...
 

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).

Author
Alvin

Function Documentation

◆ main()

int main ( void  )

main function

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

◆ test()

static void test ( )
static

Function to test the correctness of get_union() function.

Returns
void
203 {
204 tests::test1();
205 tests::test2();
206 tests::test3();
207 tests::test4();
208 tests::test5();
209 tests::test6();
210}
void test1()
< Use the BinaryTree
Definition: reverse_binary_tree.cpp:167
void test4()
A Test to check correct functionality with duplicate values.
Definition: union_of_two_arrays.cpp:149
void test3()
A Test to check correct reversal of a Binary Tree.
Definition: reverse_binary_tree.cpp:212
void test6()
A Test to check correct functionality with an array sorted using std::sort.
Definition: union_of_two_arrays.cpp:182
void test2()
A Test to check an edge case (NULL root element)
Definition: reverse_binary_tree.cpp:191
void test5()
A Test to check correct functionality with a harder test case.
Definition: union_of_two_arrays.cpp:165
Here is the call graph for this function: