Note that there are some explanatory texts on larger screens.

plurals
  1. POdelphi mergesort for string arrays
    primarykey
    data
    text
    <p>Found this coded mergesort on <a href="http://www.explainth.at/en/delphi/dsort.shtml" rel="nofollow">http://www.explainth.at/en/delphi/dsort.shtml</a> (site down but try wayback machine or this site: <a href="http://read.pudn.com/downloads192/sourcecode/delphi_control/901147/Sorts.pas__.htm" rel="nofollow">http://read.pudn.com/downloads192/sourcecode/delphi_control/901147/Sorts.pas__.htm</a>) but essentially the array defined was not for an array of string. <code>type TSortArray = array[0..8191] of Double;</code> I want to pass an array of string that would possibly eliminate duplicates (this would be Union?) <em>and preserve original order if possible for later resorting it back to original index position minus the duplicates of course (original index)</em> so array can be passed back for further processing. I am using very large files of strings with millions of strings (14 to 30 million) so <code>TStringList</code> is not an option. Best option for these large files is to use arrays of string or arrays of records (or maybe single linked list??) and sort with stable algorithm made for large amount of data.</p> <ol> <li>How can I change this to take array of string?</li> <li>How can it be further modified to delete or at least mark duplicates?</li> <li>Is it possible to store original index number to place back strings in original position?</li> <li>Are arrays of string or arrays of record better for large number of strings as compared to a single linked list?</li> </ol> <p>Questions are listed in order of importance so if you answer question number 1 only that is fine. Thank you in advance for all your input.</p> <hr> <pre><code>procedure MergeSort(var Vals:TSortArray;ACount:Integer); var AVals:TSortArray; procedure Merge(ALo,AMid,AHi:Integer); var i,j,k,m:Integer; begin i:=0; for j:=ALo to AMid do begin AVals[i]:=Vals[j]; inc(i); //copy lower half or Vals into temporary array AVals end; i:=0;j:=AMid + 1;k:=ALo;//j could be undefined after the for loop! while ((k &lt; j) and (j &lt;= AHi)) do if (AVals[i] &lt; Vals[j]) then begin Vals[k]:=AVals[i]; inc(i);inc(k); end else begin Vals[k]:=Vals[j]; inc(k);inc(j); end; {locate next greatest value in Vals or AVals and copy it to the right position.} for m:=k to j - 1 do begin Vals[m]:=AVals[i]; inc(i); end; //copy back any remaining, unsorted, elements end; procedure PerformMergeSort(ALo,AHi:Integer); var AMid:Integer; begin if (ALo &lt; AHi) then begin AMid:=(ALo + AHi) shr 1; PerformMergeSort(ALo,AMid); PerformMergeSort(AMid + 1,AHi); Merge(ALo,AMid,AHi); &lt;==== passing the array as string causes AV breakdown here end; end; begin SetLength(AVals, ACount); PerformMergeSort(0,ACount - 1); end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload