【发布时间】:2016-03-30 08:28:37
【问题描述】:
我目前正在使用 Pascal 编写一个程序,我想在该程序中实现冒泡排序算法并使用 Bars 直观地显示它。我已经成功编写了 BubbleSort 过程,但我被困在 PlotBars 过程(为 BubbleSort 过程绘制条形的过程)。现在,当我运行程序时,它会在右侧显示数字面板,然后单击“排序!”按钮它只显示一个栏,如果我一直按排序按钮,它会降低栏的高度。我附在我的代码 sn-p 和我的输出下方,并且我附在我希望我的输出看起来像的下方。任何帮助将不胜感激。谢谢
问候, 瓦利德
PltoBar 代码
procedure PlotBars(var data: array of Integer);
var
i: Integer;
yAxis: Integer;
newWidth: Single;
newHeight: Single;
roundNewWidth: Integer;
roundNewHeight: Integer;
begin
yAxis := 600; //Screenheight is 600
newWidth := ((ScreenWidth() - PanelWidth('NumberPanel')) / 25); // There are 25 index in array
for i:= 0 to High(data) do
begin
newHeight := data[i] - ScreenHeight();
roundNewWidth := Round(newWidth);
roundNewHeight := Round(newHeight);
ClearScreen();
FillRectangle(ColorRed, i, yAxis, roundNewWidth, roundNewHeight);
end;
end;
【问题讨论】:
-
代码应该作为文本插入问题,而不是图像。另外,您使用什么版本的 Pascal?
-
您应该提供一个最小、完整和可验证的示例 (stackoverflow.com/help/mcve)。您的部分代码无法编译,因为没有包含许多变量和函数。
标签: pascal