Logo 
Search:

C++ Programming FAQ

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

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

  Shared By: Sofia Hughes    Date: Oct 04    Category: C++ Programming    Views: 1570

Answer:

1. [Loop on pass index]
Repeat through step 4 for pass=1 to n-1.

2. Initialize minindex
minindex <-- pass.

3. [Make a pass and obtain element with smallest value]
Repeat for i=pass+1,pass+2,….n.
If k[i] < k[minindex]
then minindex <-- i.

4. [Exchange the elements]
If minindex!=pass
then k[pass] interchange with k[minindex].

5. Finish
return.

Share: 
 



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


Tagged: