Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

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

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 2 Anzeige

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

Herunterladen, um offline zu lesen

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();
}
.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Write a function imerge that gets pointers to two sorted integer array.docx (20)

Weitere von lez31palka (20)

Anzeige

Aktuellste (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(); }

×