?? nextfit.pas
字號:
unit NextFit;
interface
uses
Windows, ActiveX, ComObj, classes, BinIntf, BinBase;
type
TNextFit = class(TAbstractOneDBin)
procedure Optimize; override;
function GetName: WideString; override;
end;
implementation
uses
ComServ;
{ TNextFit }
function TNextFit.GetName: WideString;
begin
Result := 'Next Fit';
end;
procedure TNextFit.Optimize;
var
Index: Integer;
Item: TBinItem;
begin
FCurrentBin := nil;
for Index := 0 to FItems.Count - 1 do begin
Item := TBinItem(FItems[Index]);
if (FCurrentBin = nil) or (FCurrentBin.Value + Item.Value > FMaxValue) then begin
FCurrentBin := TBin.Create;
FBins.Add(FCurrentBin);
end;
FCurrentBin.Items.Add(Item);
FCurrentBin.Value := FCurrentBin.Value + Item.Value;
end;
FBinIndex := -1;
end;
initialization
{$IFDEF VER100}
TComObjectFactory.Create(ComServer, TNextFit, Class_NextFit,
'NextFit', 'Next Fit algorithm', ciMultiInstance);
{$ELSE}
TComObjectFactory.Create(ComServer, TNextFit, Class_NextFit,
'NextFit', 'Next Fit algorithm', ciMultiInstance, tmApartment);
{$ENDIF}
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -