Successfully reported this slideshow.
Your SlideShare is downloading. ×

Write a function imerge that gets pointers to two sorted integer array.docx

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 2 Ad

Write a function imerge that gets pointers to two sorted integer array.docx

Download to read offline

Write a function imerge that gets pointers to two sorted integer arrays src1[] and src2[] as parameters(the arrays are sorted in ascending order), merges the two arrays in ascending sorted order into a dynamic integer array dst[] and returns to dst[]
The function header is int* imerge (int * src1, int *src2)
Solution
#include <stdio.h>
#include <conio.h>
void main(){
int *arr,src1,src2,tmp,n;
int*imerge(int*src1,intsrc2)
clrscr();
printf(\"Enter how many data you want to sort : \");
scanf(\"%d\",&n);
for(src1=0;src1<nsrc1i++)
scanf(\"%d\",arr+src1);
for(src1=0;src1<n;src1++)
{
for(src2=src1+1;src2<n;src2++){
if( *(arr+src1) > *(arr+src2)){
tmp = *(arr+src1);
*(arr+src1) = *(arr+src2);
*(arr+src2) = tmp;
}
}
}
printf(\"\ \ After Sort\ \");
for(sr1=0;src1<n;src1++)
printf(\"%d\ \",*(arr+src1));
getch();
}
.

Write a function imerge that gets pointers to two sorted integer arrays src1[] and src2[] as parameters(the arrays are sorted in ascending order), merges the two arrays in ascending sorted order into a dynamic integer array dst[] and returns to dst[]
The function header is int* imerge (int * src1, int *src2)
Solution
#include <stdio.h>
#include <conio.h>
void main(){
int *arr,src1,src2,tmp,n;
int*imerge(int*src1,intsrc2)
clrscr();
printf(\"Enter how many data you want to sort : \");
scanf(\"%d\",&n);
for(src1=0;src1<nsrc1i++)
scanf(\"%d\",arr+src1);
for(src1=0;src1<n;src1++)
{
for(src2=src1+1;src2<n;src2++){
if( *(arr+src1) > *(arr+src2)){
tmp = *(arr+src1);
*(arr+src1) = *(arr+src2);
*(arr+src2) = tmp;
}
}
}
printf(\"\ \ After Sort\ \");
for(sr1=0;src1<n;src1++)
printf(\"%d\ \",*(arr+src1));
getch();
}
.

Advertisement
Advertisement

More Related Content

More from lez31palka (20)

Advertisement

Recently uploaded (20)

Write a function imerge that gets pointers to two sorted integer array.docx

  1. 1. Write a function imerge that gets pointers to two sorted integer arrays src1[] and src2[] as parameters(the arrays are sorted in ascending order), merges the two arrays in ascending sorted order into a dynamic integer array dst[] and returns to dst[] The function header is int* imerge (int * src1, int *src2) Solution #include <stdio.h> #include <conio.h> void main(){ int *arr,src1,src2,tmp,n; int*imerge(int*src1,intsrc2) clrscr(); printf("Enter how many data you want to sort : "); scanf("%d",&n); for(src1=0;src1<nsrc1i++) scanf("%d",arr+src1); for(src1=0;src1<n;src1++) { for(src2=src1+1;src2<n;src2++){ if( *(arr+src1) > *(arr+src2)){ tmp = *(arr+src1); *(arr+src1) = *(arr+src2); *(arr+src2) = tmp; } } } printf(" After Sort "); for(sr1=0;src1<n;src1++) printf("%d ",*(arr+src1));
  2. 2. getch(); }

×