// Copyright (c) 1998-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. // SortTools_ShellSort.gxx // cree le 04/11/91 par ASI // Reference : Software Conponents with ADA, Grady Booch. void SortTools_ShellSort::Sort(Array& TheArray, const Comparator& Comp) { Item TempItem; Standard_Integer Outer; Standard_Integer Inner; Standard_Integer Inc = 1; for(;;) { if((9 * Inc) + 4 >= TheArray.Upper() - TheArray.Lower() + 1) break; Inc = (Inc * 3) + 1; } for(;;) { Outer = TheArray.Lower() + Inc; for(;;) { TempItem = TheArray(Outer); Inner = Outer; while (Comp.IsLower(TempItem, TheArray(Inner - Inc))) { TheArray(Inner) = TheArray(Inner - Inc); Inner = Inner - Inc; if(Inner - Inc < TheArray.Lower()) break; } TheArray(Inner) = TempItem; if(Outer + Inc > TheArray.Upper()) break; Outer = Outer + Inc; } if(Inc == 1) break; Inc = (Inc - 1) / 3; } }