From dd808010efad76dc23cc05cc30e935e0b8ac470c Mon Sep 17 00:00:00 2001 From: Souvik Senapati Date: Tue, 18 Oct 2022 11:42:52 +0530 Subject: [PATCH] Add this problem of Merge Two sorted arrays --- Merge Two Sorted Arrays | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Merge Two Sorted Arrays diff --git a/Merge Two Sorted Arrays b/Merge Two Sorted Arrays new file mode 100644 index 0000000..db136b8 --- /dev/null +++ b/Merge Two Sorted Arrays @@ -0,0 +1,41 @@ +// C++ program to merge two sorted arrays +#include +#include +using namespace std; +void merge(int nums1[], int nums2[], int m, int n) { + //Creating an array of size m+n to store a merged array + int nums3[m+n]; + // copy nums1[] elements to nums3[] + for(int i=0;i=0;j--){ + //move elments one position ahead that are greater than current value + if(nums3[j]>temp){ + nums3[j+1]=nums3[j]; + } + else + break; + } + m=m+1; + //put Current element at its correct position. + nums3[j+1]=temp; + } + // printing the resultant array + cout << "Array after merging" <