Révision | 09043d9ca6571baeee7ba767fe2374fd11e36e36 (tree) |
---|---|
l'heure | 2021-11-24 19:07:27 |
Auteur | yamat0jp <yamat0jp@yaho...> |
Commiter | yamat0jp |
ループ構造回避
@@ -80,6 +80,7 @@ type | ||
80 | 80 | starting, stopping: TMyData; |
81 | 81 | dummy: Boolean; |
82 | 82 | complete: Boolean; |
83 | + roop: TMyData; | |
83 | 84 | function checkClick(X, Y: integer): Boolean; |
84 | 85 | function createBox(X, Y: integer): TMyData; |
85 | 86 | procedure addLine(prev, next: TMyData); |
@@ -87,6 +88,8 @@ type | ||
87 | 88 | function getTime(prev, next: TMyData): integer; |
88 | 89 | procedure setTime(obj: TMyData; reverse: Boolean); |
89 | 90 | function isCritical(line: TMyLine): Boolean; |
91 | + function isLoopDouble(prev, next: TMyData): Boolean; | |
92 | + function isLoop(item: TMyData): Boolean; | |
90 | 93 | public |
91 | 94 | { Public 宣言 } |
92 | 95 | end; |
@@ -150,7 +153,7 @@ procedure TForm1.addLine(prev, next: TMyData); | ||
150 | 153 | var |
151 | 154 | obj: TMyLine; |
152 | 155 | begin |
153 | - if (prev.next.IndexOf(next) > -1) or (next.prev.IndexOf(prev) > -1) then | |
156 | + if isLoopDouble(prev, next) = true then | |
154 | 157 | Exit; |
155 | 158 | if (dummy = true) and ((prev = starting) or (next = stopping)) then |
156 | 159 | Exit; |
@@ -288,6 +291,40 @@ begin | ||
288 | 291 | result := true; |
289 | 292 | end; |
290 | 293 | |
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 | + | |
291 | 328 | procedure TForm1.FormCreate(Sender: TObject); |
292 | 329 | begin |
293 | 330 | list := TList<TMyData>.Create; |