/end main(/display sorted array /end class shellsortapp in main(we create an object of type arrayshcapable of holding itemsfill it with random datadisplay itshellsort itand display it again here' some sample outputa= = you can change maxsize to higher numbersbut don' go too high , items take fraction of minute to sort the shellsort algorithmalthough it' implemented in just few linesis not simple to follow to see the details of its operationstep through -item sort with the workshop appletcomparing the messages generated by the applet with the code in the shellsort(method other interval sequences picking an interval sequence is bit of black art our discussion so far used the formula = * + to generate the interval sequencebut other interval sequences have been used with varying degrees of success the only absolute requirement is that the diminishing sequence ends with so the last pass is normal insertion sort in shell' original paperhe suggested an initial gap of / which was simply divided in half for each pass thus the descending sequence for = is this approach has the advantage that you don' need to calculate the sequence before the sort begins to find the initial gapyou just divide by howeverthis turns out not to be the best sequence although it' still better than the insertion sort for most datait sometimes degenerates to ( running timewhich is no better than the insertion sort better approach is to divide each interval by instead of for = this leads to this is considerably better than dividing by as it avoids some worst case circumstances that lead to ( behavior some extra code is needed to ensure that the last value in the sequence is no matter what is this gives results comparable to knuth' sequence shown in the listing another possibility for descending sequence (from flamigsee appendix "further reading"is if( else ( * - it' generally considered important that the numbers in the interval sequence are relatively primethat isthey have no common divisors except this makes it more likely that each pass will intermingle all the items sorted on the previous pass the inefficiency of shell' original / sequence is due to its failure to adhere to this rule you may be able to invent gap sequence of your own that does just as well (or possibly even betterthan those shown whatever it isit should be quick to calculate so as not to slow down the algorithm