1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-21 10:55:33 +03:00
occt/src/SortTools/SortTools_HeapSort.gxx
bugmster 973c2be1e1 0024428: Implementation of LGPL license
The copying permission statements at the beginning of source files updated to refer to LGPL.
Copyright dates extended till 2014 in advance.
2013-12-17 12:42:41 +04:00

67 lines
1.9 KiB
Plaintext

// 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 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_HeapSort.gxx
// cree le 04/11/91 par ASI
// Reference : Software Conponents with ADA, Grady Booch.
void Shift(Array& TheArray,
const Comparator& Comp,
const Standard_Integer Left, const Standard_Integer Right)
{
Item Temp = TheArray(Left);
Standard_Integer Front = Left;
Standard_Integer Back = Front * 2;
while (Back <= Right) {
if (Back < Right) {
if(Comp.IsLower(TheArray(Back), TheArray(Back + 1))) {
Back = Back + 1;
}
}
if(!Comp.IsLower(Temp, TheArray(Back))) break;
TheArray(Front) = TheArray(Back);
Front = Back;
if(Front * 2 > TheArray.Upper()) break;
Back = Front * 2;
}
TheArray(Front) = Temp;
}
void SortTools_HeapSort::Sort(Array& TheArray,
const Comparator& Comp)
{
Item TempItem;
Standard_Integer Left;
Standard_Integer Right;
Left = ((TheArray.Upper() - TheArray.Lower() + 1) / 2) + 1;
Right = TheArray.Upper();
while (Left > TheArray.Lower()) {
Left = Left - 1;
Shift(TheArray, Comp, Left, Right);
}
while (Right > TheArray.Lower()) {
TempItem = TheArray(TheArray.Lower());
TheArray(TheArray.Lower()) = TheArray(Right);
TheArray(Right) = TempItem;
Right = Right - 1;
Shift(TheArray, Comp, Left, Right);
}
}