Código
type TValue = record iFlags: Integer; fValue: real; end; TArrayValue = Array Of TValue; TPila = class(TObject) private udtArray: TArrayValue; // Array Of TValue public constructor Create(); overload; constructor Create(var oPila: TPila); overload; procedure Push(udtVar: TValue); overload; procedure Push(fValue: Real; iFlags: Integer); overload; function Pop(): TValue; function Count(): Integer; function Get(Index: Integer): TValue; procedure Invert(); procedure Clear(); procedure Clone(var oPila: TPila); end; implementation constructor TPila.Create(); begin Self.Clear; end; constructor TPila.Create(var oPila: TPila); begin Self.Clone(oPila); end; procedure TPila.Push(fValue: Real; iFlags: Integer); var iLength: Integer; iIndex: Integer; begin iIndex := Self.Count; iLength := (iIndex + 1); SetLength(Self.udtArray, iLength); udtArray[iIndex].iFlags := iFlags; udtArray[iIndex].fValue := fValue; end; procedure TPila.Push(udtVar: TValue); begin Push(udtVar.fValue, udtVar.iFlags); end; function TPila.Pop(): TValue; var iNewLength: Integer; udtRet: TValue; begin if (Self.Count = 0) then begin udtRet.iFlags := 0; udtRet.fValue := 0; end else begin iNewLength := High(Self.udtArray); udtRet := Self.udtArray[iNewLength]; SetLength(Self.udtArray, iNewLength); end; Result := udtRet; end; function TPila.Count(): Integer; begin Result := Length(Self.udtArray); end; procedure TPila.Invert(); var i: Integer; j: Integer; begin if not (Count = 0) then begin j := High(Self.udtArray); for i:= Low(Self.udtArray) to (High(Self.udtArray) div 2) do begin SwapFloat(Self.udtArray[i].fValue, Self.udtArray[j].fValue); SwapInt(Self.udtArray[i].iFlags, Self.udtArray[j].iFlags); j := (j - 1); end; end; end; function TPila.Get(Index: Integer): TValue; var udtRet: TValue; begin if (Index < Self.Count) then begin udtRet := Self.udtArray[Index]; end else begin udtRet.iFlags := 0; udtRet.fValue := 0; end; Result := udtRet; end; procedure TPila.Clear(); begin SetLength(Self.udtArray, 0); end; procedure TPila.Clone(var oPila: TPila); begin oPila.udtArray := Self.udtArray; end;