Hi All, I am trying to use some legacy Delphi QuickSort code. The problem is that the original defines this var: Var d : ptrArray Absolute da;and I have changed this in my version and it crashes with an error. Project Island_maker.exe raised exception class 'External SIGSEGV' I am trying to use my version of the code, not the original. Original code ---Unit Qsort; { Copyright 1990 Trevor J CarlsenAll rights reserved. Author: Trevor J Carlsen PO Box 568 Port Hedland WA 6721 A general purpose sorting Unit.
} Interface Type updown = (ascending,descending); str255 = String; dataType = str255; { the Type of data to be sorted } dataptr = ^dataType; ptrArray = Array[1..10000] of dataptr; Arrayptr = ^ptrArray; Const maxsize : Word = 10000; SortType : updown = ascending; Procedure QuickSort(Var da; left, right : Word); {============================================================================}Implementation Procedure swap(Var a,b : dataptr); { Swap the Pointers } Var t : dataptr; begin t := a; a := b; b := t; end; Procedure QuickSort(Var da; left,right : Word); Var d : ptrArray Absolute da; pivot : dataType; lower, upper, middle : Word; begin lower := left; upper := right; middle:= (left + right) div 2; pivot := d[middle]^; Repeat Case SortType of ascending : begin While d[lower]^ < pivot do inc(lower); While pivot < d[upper]^ do dec(upper); end; descending: begin While d[lower]^ > pivot do inc(lower); While pivot > d[upper]^ do dec(upper); end; end; { Case } if lower <= upper then begin { swap the Pointers not the data } swap(d[lower],d[upper]); inc(lower); dec(upper); end; Until lower > upper; if left < upper then QuickSort(d,left,upper); if lower < right then QuickSort(d,lower,right); end; { QuickSort } end. My version-----Type map_detail = record Terrain : Terrain_type; Terrain_char : char; description : string; x, y, location_number : integer; exits : exit_type; end; island_single_type = array[ 1..(array_max_x * array_max_y) ] of map_detail; Type updown = (ascending, descending); Const SortType : updown = ascending; var Form1: TForm1; max_x, max_y, max_locations, start_x, start_y, finish_x, finish_y : integer; island : island_2D_type; island_single_array : island_single_type; implementation uses set_max; {--------------------------------------------------------------------} Procedure swap(Var a,b : map_detail); { Swap the Pointers } Var t : map_detail; begin t := a; a := b; b := t; end;{--------------------------------------------------------------------} Procedure QuickSort( Var island_single_array : island_single_type; left, right : integer); Var d : island_single_type; pivot : integer; lower, upper, middle : integer; begin lower := left; upper := right; middle:= (left + right) div 2; pivot := island_single_array[middle].location_number; Repeat Case SortType of ascending : begin While island_single_array[lower].location_number < pivot do inc(lower); While pivot < island_single_array[upper].location_number do dec(upper); end; descending: begin While island_single_array[lower].location_number > pivot do inc(lower); While pivot > island_single_array[upper].location_number do dec(upper); end; end; { Case } if lower <= upper then begin { swap the Pointers not the data } swap(d[lower],d[upper]); inc(lower); dec(upper); end; Until lower > upper; if left < upper then QuickSort(d,left,upper); if lower < right then QuickSort(d,lower,right); end; { QuickSort }{--------------------------------------------------------------------}-----
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus