Data Structure: How to implement Shell Sort in C++?

Shell is generalization of insertion sort and is devised by Donald Shell in 1954. The method sorts separate sub-files of original file i.e.

  • Divide the original file into smaller sub-files.
  • Sort individual sub-files using any sorting algorithm

We choose increment ‘k’ for dividing the original file into smaller sub-files and process is repeated until k becomes 1.

Source Code:

Output:

 

How many elements? 7
Insert array of element to sort: 75 12 36 35 25 99 62
Iteration : 1 Span = 7 : 75 12 36 35 25 99 62
Iteration : 2 Span = 3 : 35 12 36 62 25 99 75
Iteration : 3 Span = 1 : 12 25 35 36 62 75 99

SHARE Data Structure: How to implement Shell Sort in C++?

You may also like...

1 Response

  1. Anonymous says:

    Please comment this code. I am having trouble understanding this sorting algorithm, and nicely commented code would help immensely.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share