|
C
For Swimmers : Mastering C step-by-step |
|
|
|
Shell
Sort
|
|
Definition :
Shell
Sort is a simple extension of Insertion
sort. Its speed comes from the fact that it exchanges
elements that are far apart (the insertion sort exchanges
only adjacent elements).
The
idea of the Shell sort is to rearrange the file to give it
the property that taking every hth
element (starting anywhere) yields a sorted file. Such a
file is said to be h-sorted.
|
ALGORITHM : SHELL
SORT
Procedure ShellSort(A, MAX) : Here
A is an array consisting of MAX elements. This procedure
sorts the elements in Ascending Order by repeatedly
exchanging elements that are far apart, if necessary. Here 'temp' is a temporary
variable used to exchange the elements in this
procedure.
ASCENDING
ORDER
for h = 1 to h £
MAX/9 do
for (; h > 0; h != 3) do
for i = h+1 to
i £ MAX do
v = A[i]
j = i
while (j > h AND A[j-h] > v)
A[i] = A[j-h]
j = j - h
A[j] = v
i = i + 1
|
|
|
|
FREE
Source Code
Click
Here: Shell Sort - Ascending Order
|
|
|
Click
Here : To learn more about Shell Sort
|
|
|
|
You are
Visitor No. 
Sign
my Guestbook
View
my Guestbook
Thanks for using C For Swimmers.
Regarding this material, you can send Bug Reports,
Suggestions, Comments, etc. to
nandakishorkn@rediffmail.com
|