Thursday, 18 July 2013

Algorithm for Merging Two Arrays

  1. Create three arrays a1[100],a2[100],a3[200]
  2. Enter the elements p and q in ascending order in a1 and a2
  3. Initialize m and n(lower bound to 0)
  4. Check if(a[m]<=b[n])[Assign elements of array a1 to a3] a3[c]=a2[n+1]Set c= c+1Else[Assign elements of a2 to a3] a3[c]= a2[n++]Set c= c+1[End of If Structure]
  5. Assign remaining elements of a1 and a2 to a3
  6. Display the elements of a3
  7. End

No comments:

Post a Comment