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

Function Merge

Arrays/31_Menu_for_Array.c:462–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462struct array* Merge(struct array *arr,struct array *arr2)
463{
464 int i,j,k;
465 i=j=k=0;
466 struct array *arr3=(struct array *)malloc(sizeof(struct array));
467 while(i<arr->length && j<arr2->length)
468 {
469 if(arr->A[i]<arr2->A[j])
470 {
471 arr3->A[k]=arr->A[i];
472 i++;k++;
473 }
474 else
475 {
476 arr3->A[k]=arr2->A[j];
477 j++;k++;
478 }
479 }
480 for(;i<arr->length;i++)
481 {
482 arr3->A[k]=arr->A[i];
483 k++;
484 }
485 for(;j<arr2->length;j++)
486 {
487 arr3->A[k]=arr2->A[j];
488 k++;
489 }
490 arr3->size=arr->size+arr2->size;
491 arr3->length=arr->length+arr2->length;
492 return arr3;
493}
494
495
496

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected