MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / Merge

Method Merge

Arrays/18_Menu_Based_problem.cpp:233–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231
232}
233Array* Array::Merge(Array arr2)
234{
235 int i,j,k;
236 i=j=k=0;
237
238 Array *arr3=new Array(length+arr2.length);
239
240 while(i<length && j<arr2.length)
241 {
242 if(A[i]<arr2.A[j])
243 arr3->A[k++]=A[i++];
244 else
245 arr3->A[k++]=arr2.A[j++];
246 }
247 for(;i<length;i++)
248 arr3->A[k++]=A[i];
249 for(;j<arr2.length;j++)
250 arr3->A[k++]=arr2.A[j];
251 arr3->length=length+arr2.length;
252
253 return arr3;
254}
255Array* Array::Union(Array arr2)
256{
257 int i,j,k;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected