Algorithm to merge two sorted arrays with third array, Data Structure & Algorithms

Q. Write down an algorithm to merge the two sorted arrays into the third array. Do  not perform the sort function in the third array.                          

Ans:

void merge(int *a,int *b,int n,int m)

{

int i=0,c[20],j=0,k=0,count=0;

while(i<=n&&j<=m)

{

if(a[i]

{

c[k]=a[i];

i++;

k++;

}

if(a[i]>b[j])

{

c[k]=b[j];

j++;

k++;

}

if(a[i]==b[j])

{

c[k]=a[i];

k++; i++; j++;

count++;

}

}

if(i<=n&&j==m)

{

while(i<=n)

{

c[k]=a[i];

i++;

k++;

}

}

if(i==n&&j<=m)

{

while(j<=m)

{

c[k]=b[j];

i++;

j++;

}

}

for(i=0;i

printf("%d\t",c[i]);

}

Posted Date: 7/10/2012 7:07:26 AM | Location : United States







Related Discussions:- Algorithm to merge two sorted arrays with third array, Assignment Help, Ask Question on Algorithm to merge two sorted arrays with third array, Get Answer, Expert's Help, Algorithm to merge two sorted arrays with third array Discussions

Write discussion on Algorithm to merge two sorted arrays with third array
Your posts are moderated
Related Questions
Full Binary Trees: A binary tree of height h that had 2h -1 elements is called a Full Binary Tree. Complete Binary Trees: A binary tree whereby if the height is d, and all of

draw a flowchart which prints all the even numbers between 1-50

What do you mean by hashing? Hashing gives the direct access of record from the file no matter where the record is in the file. This is possible with the help of a hashing func

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Define the terms     i) Key attribute     ii) Value set  Key attribute:  An entity  type  usually  has  an attribute  whose  values  are  distinct  fr

Write a detailed description of a function that takes in an integer as an argument, then prints out the squares of all positive integers whose squares are less than the input. (The

The searching method are applicable to a number of places in current's world, may it be Internet, search engines, text pattern matching, on line enquiry, finding a record from data

Algorithm for Z-Buffer Method (a)  Initialize every pixel in the viewport to the smallest value of z, namely z0 the z-value of the rear clipping plane or "back-ground". Store a

Construct G for α, n, and W given as command line parameters. Throw away edges that have an asymmetric relation between nodes. That is, if A is connected to B, but B is not connect

How can the third dimension be displayed on the screen The main problem in visualization is the display of three-dimensional objects and scenes on two-dimensional screens. How