Page 257 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 257
Advanced Data Structure and Algorithms
Notes }
}
void merge(int a[],int b[],int c[],int k)
{
int ptra=0,ptrb=0,ptrc=0;
while(ptra<k && ptrb<k)
{
if(a[ptra] < b[ptrb])
{
c[ptrc]=a[ptra];
ptra++;
}
else
{
c[ptrc]=b[ptrb];
ptrb++;
}
ptrc++;
}
while(ptra<k)
{
c[ptrc]=a[ptra];
ptra++;ptrc++;
}
while(ptrb<k)
{
c[ptrc]=b[ptrb];
ptrb++; ptrc++;
}
}
Input: Enter the elements of the fi rst list
10 20 25 50 63
Output: The elements of first list are
20 25 50 63
Input: Enter the elements of the second list
16 62 68 80
Output: The elements of second list are
12 16 62 68 80
The sorted list a is
63 50 25 20 10
252 LOVELY PROFESSIONAL UNIVERSITY