Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Merge Sort in dfs (data file structure).

  Shared By: Brandon Evans    Date: Jan 24    Category: C++ Programming    Views: 1428

Answer:

1. [Initialization]
i <-- first
j <-- second
k <-- 0.

2. [Compare corresponding element and output smallest]
while i<second and j>=third
if k[i] <= k[j]
then l <-- l + 1
s[l] <-- k[i]
i <-- i + 1
else
l <-- l + 1
s[l] <-- k[j]
j <-- j + 1.

3. [Copy the remaining elements]
if i >=second
then repeat while j<=third
l <-- l + 1
s[l] <-- k[j]
j <-- j + 1.
else
repeat while i<second
l <-- l + 1
s[l] <-- k[i]
i <-- i + 1.

Share: 
 



Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: