⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 银行家算法 界面很有友好 很详细的 希望大家去看看
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clGreen;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clGreen;
                image3.Canvas.Brush.Color:=clGreen;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clGreen;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         4: if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clOlive;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clOlive;
                image2.Canvas.Brush.Color:=clOlive;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clOlive;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clOlive;
                image3.Canvas.Brush.Color:=clOlive;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clOlive;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         5:if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clMoneyGreen;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clMoneyGreen;
                image2.Canvas.Brush.Color:=clMoneyGreen;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clMoneyGreen;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clMoneyGreen;
                image3.Canvas.Brush.Color:=clMoneyGreen;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clMoneyGreen;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         6: if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clTeal;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clTeal;
                image2.Canvas.Brush.Color:=clTeal;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clTeal;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clTeal;
                image3.Canvas.Brush.Color:=clTeal;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clTeal;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         7:  if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clPurple;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clPurple;
                image2.Canvas.Brush.Color:=clPurple;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clPurple;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clPurple;
                image3.Canvas.Brush.Color:=clPurple;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clPurple;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         8: if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clLime;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clLime;
                image2.Canvas.Brush.Color:=clLime;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clLime;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clLime;
                image3.Canvas.Brush.Color:=clLime;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clLime;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         9: if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clYellow;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clYellow;
                image2.Canvas.Brush.Color:=clYellow;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clYellow;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clYellow;
                image3.Canvas.Brush.Color:=clYellow;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clYellow;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

         10:  if clNum=1 then //从第一个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image1.Canvas.Brush.Color:=clFuchsia;
                image1.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=1) then//第一个image不够画
              begin
                image1.Canvas.Brush.Color:=clFuchsia;
                image2.Canvas.Brush.Color:=clFuchsia;
                image1.Canvas.Rectangle(0,PixelStart,70,300);
                image2.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=2 then//从第二个image开始画
            begin
              if (clNumEnd=-1) then
              begin
                image2.Canvas.Brush.Color:=clFuchsia;
                image2.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
              end
              else if(clNumend=2) then//第二个image不够画
              begin
                image2.Canvas.Brush.Color:=clFuchsia;
                image3.Canvas.Brush.Color:=clFuchsia;
                image2.Canvas.Rectangle(0,PixelStart,70,300);
                image3.Canvas.Rectangle(0,0,70,PixelEnd);
              end;
            end
            else if clNum=3 then  //从第三个image开始画
            begin
              image3.Canvas.Brush.Color:=clFuchsia;
              image3.Canvas.Rectangle(0,PixelStart,70,PixelStart+PixelHeight);
            end;

       end;//end case

     end;
   end;//end for

   //更新edit的显示
   IntToText;
   //更新table的显示
   AddToTable;
end;

function TForm1.HandUpWork(NowWork: integer): boolean;
var
  i,j:integer;
  flag:boolean;
begin
  //释放已完成作业
  for i:=0 to 9 do
    if (group[i].Finish='运行') and (group[i].ReachTime+group[i].DoTime<=group[NowWork].ReachTime) then
       DeleteWork(i);

  //新作业提交
  group[NowWork].Finish:='运行';
  flag:=false;
  for i:=0 to Num-1 do
  begin
    if table[i].Size>group[NowWork].size then  //还剩空间
    begin
       //已分配表
       tableed[numed].Number:=numed;
       tableed[numed].Size:=group[NowWork].size;
       tableed[numed].Position:=table[i].Position;
       tableed[numed].WorkNum:=NowWork+1;
       tableed[numed].finish:='已分配';//已分配
       numed:=numed+1;

       //未分配表
       table[i].Position:=table[i].Position+group[NowWork].size;
       table[i].Size:=table[i].Size-group[NowWork].size;

       //作业
       group[NowWork].Position:=tableed[numed-1].Position;
       group[NowWork].Finish:='运行';
       flag:=true;
       break;
    end
    else if table[i].Size=group[NowWork].size then //空间为0,删除
    begin
       //已分配表
       tableed[numed].Number:=numed;
       tableed[numed].Size:=group[NowWork].size;
       tableed[numed].Position:=table[i].Position;
       tableed[numed].WorkNum:=NowWork+1;
       tableed[numed].finish:='已分配';//已分配
       numed:=numed+1;
       
       //作业
       group[NowWork].Position:=tableed[numed-1].Position;
       group[NowWork].Finish:='运行';

       //未分配表  删除该记录
       for j:=i to num-1 do
       begin
         table[j+1].Number:=table[j+1].Number-1;
         table[j]:=table[j+1];
       end;
       num:=num-1;
       //按size大小升序table
       OrderTable;
       flag:=true;
       break;
    end;  //end if
  end; //end for

  if flag=false then   //找不到可分配的空间,程序终止
  begin
    ShowMessage('因为没有空间被分配,所以分配停止!');
    exitData:=true;
    result:=false;
  end;

  result:=true;
end;

procedure TForm1.DeleteWork(WorkNum: integer);   //有错
var
  NowPosition,i,j,FrontPosition,BehindPosition,size:integer;
  MidNumber,Midsize,MidPosition,MidworkNum:integer;
  Midfinish:string;
  MidPos,length,start:integer;
begin
  group[WorKNum].Finish:='完成';

  //当前作业在talbeed中的finish改为'空项';
  for i:=0 to numed-1 do
    if tableed[i].Position=group[WorkNum].Position then
      tableed[i].finish:='空项';

  //按size大小升序table
  OrderTable;
  //将这块空间插入table中
  table[num].Number:=num+1;
  table[num].Size:=group[WorkNum].size;
  table[num].Position:=group[WorkNum].Position;
  table[num].finish:='可用';
  num:=num+1;

  //按Position大小升序table
  for i:=0 to num-2 do
    for j:=i+1 to num-1 do
      if(table[i].Position>table[j].Position) then
      begin
         Midnumber:=table[i].Number;
         Midsize:=table[i].Size;
         Midposition:=table[i].Position;
         Midworknum:=table[i].WorkNum;
         Midfinish:=table[i].finish;

         table[i]:=table[j];

         table[j].Number:=Midnumber;
         table[j].Size:=Midsize;
         table[j].Position:=Midposition;
         table[j].WorkNum:=Midworknum;
         table[j].finish:=Midfinish;
      end;

  //当前作业在未分配表talbe中的位置NowPosition;
  for i:=0 to num-1 do
    if group[WorkNum].Position=table[i].Position then
    begin
      NowPosition:=i;
      break;
    end;


  FrontPosition:=-1;
  //往后查看有没有空白区
  i:=NowPosition-1;
  MidPos:=group[WorkNum].Position;
  while(i>=0) do
  begin
    if(MidPos-table[i].Position=table[i].Size)then
    begin
      FrontPosition:=i;
      MidPos:=table[i].Position;
      i:=i-1;
    end
    else break;
  end;

  BehindPosition:=-1;
  //往前查看有没有空白区
  i:=NowPosition+1;
  MidPos:=group[WorkNum].Position+group[worknum].size;
  while(i<num) do
  begin
    if(table[i].Position=MidPos)then
    begin
      BehindPosition:=i;
      MidPos:=table[i].Position+table[i].size;
      i:=i+1;
    end
    else break;
  end;

  //相邻有空白区
  if (BehindPosition=-1) and (FrontPosition<>-1) then
  begin
    size:=0;
    for j:=FrontPosition to NowPosition do
      size:=size+table[j].Size;
    table[FrontPosition].Size:=size;

    length:=NowPosition-FrontPosition;
    for i:=0 to length-1 do
    begin
      start:=FrontPosition+1;
      while start+1<=num-1 do
      begin
        table[start+1].Number:=table[start+1].Number-1;
        table[start]:=table[start+1];
        start:=start+1;
      end;
      num:=num-1;
    end;//end for;
  end;

  if (BehindPosition<>-1) and (FrontPosition=-1) then
  begin
    //合并FrontPosition到BehindPosition之间的区域
    size:=0;
    for j:=NowPosition to BehindPosition do
      size:=size+table[j].Size;
    table[NowPosition].Size:=size;

    length:=BehindPosition-NowPosition;
    for i:=0 to length-1 do
    begin
      start:=NowPosition+1;
      while start+1<=num-1 do
      begin
        table[start+1].Number:=table[start+1].Number-1;
        table[start]:=table[start+1];
        start:=start+1;
      end;
      num:=num-1;
    end;//end for;
  end;

  if (BehindPosition<>-1) and (FrontPosition<>-1) then
  begin
    //合并FrontPosition到BehindPosition之间的区域
    size:=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -