Logo 
Search:

C++ Programming FAQ

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

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

  Shared By: Abelardo Fischer    Date: Jan 03    Category: C++ Programming    Views: 5112

Answer:

1. Initialize last <-- N.

2. [Loop on pass index]
Repeat through step 5 for pass=1,2…n-1.

3. [Initialize exchange ctr for this pass]
exchs <-- 0.

4. [Perform pair wise comparison on unsorted elements]
Repeat for i=1,2,….last - 1.
If k[i] > k[I+1]
then interchange both of them.
exchs <-- exchs + 1.

5. [Check for Exchanges]
If exchs=0
then return [mission complete early]
else
last <-- last – 1.

6. Finish
return.

Share: 
 



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


Tagged: