1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: // Programming Problem 8.
6: void shellSort(ItemType theArray[], int n)
7: {
8: for (int h = n / 2; h > 0; h = h / 2)
9: {
10: for (int unsorted = h; unsorted < n; unsorted++)
11: {
12: ItemType nextItem = theArray[unsorted];
13: int loc = unsorted;
14: while ( (loc >= h) && (theArray[loc - h] > nextItem) )
15: {
16: theArray[loc] = theArray[loc - h];
17: loc = loc - h;
18: } // end while
19: theArray[loc] = nextItem;
20: } // end for
21: } // end for
22: } // end shellSort