Ich habe eine Klasse TGraph, in der befindet sich ein
array of Tpoint names points, jetzt möchte ich dieses array per mergesort nach den x werten sortieren, jedoch bekomme ich eine ungültige zeigeroperation, was stimmt nicht ?
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
| procedure TGraph.Sort; procedure MergeSort(l, r: integer); var x, y, z, mid: integer; iarr: array of TPoint; begin SetLength(iarr, r); if (r - l > 0) then begin mid := (r + l) div 2 ; MergeSort(l, mid); MergeSort(mid + 1, r); for x := mid downto l do iarr[x] := points[x]; for y := mid + 1 to r do iarr[r + mid + 1 - y] := points[y]; x := l; y := r; for z := l to r do begin if iarr[x].x < iarr[y].x then begin points[z] := iarr[x]; inc(x); end else begin points[z] := iarr[y]; dec(y); end; end; end end; begin MergeSort(0, high(points)); end; |
Vielen Dank schonmal
