Program to perform MERGING in C++
/************************************************/ /**********PROGRAM TO PERFORM MERGING*********/ /************************************************/
#include < stdio.h> #include < conio.h>
void main() { int a[10],b[10],c[20],m,n,loop,i,j,k; clrscr(); printf("Enter the size of array a:"); scanf("%d",&m); printf("\nEnter the size of array b:"); scanf("%d",&n); printf("\nEnter the elements of array a in sorted order:\n"); for(i=0;i { scanf("%d",&a[i]); } printf("\nEnter the elements of array b in sorted order:\n"); for(i=0;i { scanf("%d",&b[i]); } loop=m+n; j=0; k=0; for(i=0;i { if(a[j] { c[i]=a[j]; j++; } else { c[i]=b[k]; k++; } if((j==m)||(k==n)) { break; } }
i=i+1; if(j==m) { for(;i { c[i]=b[k]; k++; } } else { for(;i { c[i]=a[j]; j++; } } printf("\nAfter merging the elements are:\n"); for(i=0;i { printf("%6d",c[i]); } getch(); }
http://
http://
Contributed by:
Rohit kakria
I am software developer
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=335
Click here to go on website
|