Program to perform MERGING in C++
|
Download Attachment
|
/************************************************/ /**********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(); }
|
|
|
|
|
Share this article
| Print |
Article read by 2443 times
|
|
|