Commit MetaInfo

Révision09043d9ca6571baeee7ba767fe2374fd11e36e36 (tree)
l'heure2021-11-24 19:07:27
Auteuryamat0jp <yamat0jp@yaho...>
Commiteryamat0jp

Message de Log

ループ構造回避

Change Summary

Modification

--- a/Unit1.pas
+++ b/Unit1.pas
@@ -80,6 +80,7 @@ type
8080 starting, stopping: TMyData;
8181 dummy: Boolean;
8282 complete: Boolean;
83+ roop: TMyData;
8384 function checkClick(X, Y: integer): Boolean;
8485 function createBox(X, Y: integer): TMyData;
8586 procedure addLine(prev, next: TMyData);
@@ -87,6 +88,8 @@ type
8788 function getTime(prev, next: TMyData): integer;
8889 procedure setTime(obj: TMyData; reverse: Boolean);
8990 function isCritical(line: TMyLine): Boolean;
91+ function isLoopDouble(prev, next: TMyData): Boolean;
92+ function isLoop(item: TMyData): Boolean;
9093 public
9194 { Public 宣言 }
9295 end;
@@ -150,7 +153,7 @@ procedure TForm1.addLine(prev, next: TMyData);
150153 var
151154 obj: TMyLine;
152155 begin
153- if (prev.next.IndexOf(next) > -1) or (next.prev.IndexOf(prev) > -1) then
156+ if isLoopDouble(prev, next) = true then
154157 Exit;
155158 if (dummy = true) and ((prev = starting) or (next = stopping)) then
156159 Exit;
@@ -288,6 +291,40 @@ begin
288291 result := true;
289292 end;
290293
294+function TForm1.isLoop(item: TMyData): Boolean;
295+var
296+ temp: TMyData;
297+begin
298+ result := false;
299+ if item.next.Count = 0 then
300+ Exit
301+ else if item.next.IndexOf(roop) > -1 then
302+ begin
303+ result := true;
304+ Exit;
305+ end
306+ else
307+ for temp in item.next do
308+ if isLoop(temp) = true then
309+ begin
310+ result := true;
311+ break;
312+ end;
313+end;
314+
315+function TForm1.isLoopDouble(prev, next: TMyData): Boolean;
316+var
317+ item: TMyLine;
318+begin
319+ result := false;
320+ for item in list2 do
321+ if (prev = item.prev) and (next = item.next) then
322+ result := true;
323+ roop := prev;
324+ if isLoop(next) = true then
325+ result := true;
326+end;
327+
291328 procedure TForm1.FormCreate(Sender: TObject);
292329 begin
293330 list := TList<TMyData>.Create;
Afficher sur ancien navigateur de dépôt.