You are on page 1of 5

4/14/13

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction

i t s t ud ent j unct i on
This site w ill be shortly
www.itstude ntjunction.com

Sear c h web

lab manuals solved programs -lab solutions- Lab programs C programming, java, data structures, dbms, oracle, html, advanced java, C++, Assembly language, linux, unix > Data structures programs >

Home IG NOU MCA-BCA ASSIG NME NT S 2 0 1 1 La b Ma nua l solve d P rogra ms * Que stion p a p e rs E xa m he lp * IT Softwa re se mina rs Softwa re P roj e cts, Minip roj e cts P rogra mming T utoria ls Ca re e rs-j ob sInte rvie whe lp La p top s P e rsona l Comp ute rs E xtra s

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS

#include<stdio.h> int *a[100],*b[100],*c[100],i,j,k,item1,item2; void main() { clrscr(); printf("\n Enter the number of elements in the first array\n"); scanf("%d",&item1); printf("\n Enter %d numbers\n",item1);

Ad mission notifica tions 2 0 1 1 IIIT IIT NIT E ngine e ring, MCA, MBA colle ge s mca sylla b us a ll unive rsity unive rsitie s

for(i=0;i<item1;++i) scanf("%d",&a[i]); printf("\n Enter the number of elements in the second array\n"); scanf("%d",&item2); printf("\n Enter %d numbers\n",item2); for(i=0;i<item2;++i)

data structures in c data structures lab programs data structures lab manual program of data structure Data structure programs in c Data structure

scanf("%d",&b[i]); input1(); input2(); sort();


1/5

https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-implement-2-way-merge-sort-using-pointers

4/14/13

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction

programs using c Data structures programs using c data structures programs in c data structure programs data structures using c C programs examples data structures programs c lab programs java programs java lab programs

printf("Sorted merged array is:\n"); display(); }

input1() { bsort(a,item1); printf("\n Sorted first array\n"); for(i=0;i<item1;++i) printf("%d\n",a[i]); }

input2() { bsort(b,item2); printf("\n Sorted second array\n"); for(i=0;i<item2;++i)

printf("%d\n",b[i]); }

bsort(int *m[],int n) { int swap=1,*temp; for(i=0;i<n && swap==1;++i)


https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-implement-2-way-merge-sort-using-pointers 2/5

4/14/13

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction

{ swap=0; for(j=0;j<n-(i+1);++j) if (m[j]>m[j+1]) { temp=m[j]; m[j]=m[j+1]; m[j+1]=temp; swap=1; } } }

display() { for (i=0;i<item1+item2;++i) printf("%d\n",c[i]); }

sort() { int i,j,k; i=j=k=0; while ((i<item1)&& (j<item2)) { if (a[i]<b[j]) { c[k]=a[i]; i++; k++;
https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-implement-2-way-merge-sort-using-pointers 3/5

4/14/13

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction

} else { if (a[i]>b[j]) { c[k]=b[j]; j++; k++; } else { c[k]=a[i]; i++; j++; k++; } } } while(i<item1) { c[k]=a[i]; i++; k++; } while(j<item2) { c[k]=b[j]; j++; k++; }
https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-implement-2-way-merge-sort-using-pointers 4/5

4/14/13

PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction

} }

Comments

Sign in | Report Abuse | Print Page | Remove Access | Powered By Go o g le Sites

https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-implement-2-way-merge-sort-using-pointers

5/5

You might also like