Logo 
Search:

C++ Programming FAQ

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

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

  Shared By: Lurlene Fischer    Date: Dec 11    Category: C++ Programming    Views: 2834

Answer:

1. [Initialization]
temp
key <-- 1
ctr

2. [Following loop makes the elements sortarray [0] through sortarray [key] in order by inserting the element sortarray [key] at its pos. initially sortarray [0] may be through of as sorted array].

Repeat while key < size
temp <-- sortarray [key]
ctr <-- key – 1

Repeat while ctr >=0 and tamp <sortarray [ctr]
sortarray [ctr+1] <-- sortarray [ctr]
ctr--
sortarray [ctr+1] <-- temp
key++.

Share: 
 



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


Tagged: