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

Method Union

Arrays/18_Menu_Based_problem.cpp:255–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253 return arr3;
254}
255Array* Array::Union(Array arr2)
256{
257 int i,j,k;
258 i=j=k=0;
259
260 Array *arr3=new Array(length+arr2.length);
261
262 while(i<length && j<arr2.length)
263 {
264 if(A[i]<arr2.A[j])
265 arr3->A[k++]=A[i++];
266 else if(arr2.A[j]<A[i])
267 arr3->A[k++]=arr2.A[j++];
268 else
269 {
270 arr3->A[k++]=A[i++];
271 j++;
272 }
273 }
274 for(;i<length;i++)
275 arr3->A[k++]=A[i];
276 for(;j<arr2.length;j++)
277 arr3->A[k++]=arr2.A[j];
278
279 arr3->length=k;
280
281 return arr3;
282}
283Array* Array::Inter(Array arr2)
284{
285 int i,j,k;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected