Board index » delphi » sorting files

sorting files

I need to write a very simple application that simply sorts and resorts a
comma delimited flat file, anyone point me at a simple tutorial URL or a
book?

I have Delphi 4, and very low level of Pascal skills!

 

Re:sorting files


Well it's a lot simpler if you can load each line into an array and sort
in memory.  Lets say you have ten elements in each line, 100 lines, and
you want to sort on say name, which is the 3rd field.  

array is array[1..100, 1..10] of string;
temparray is [1..10] of string;

x := 3 {3rd field}
for i:= 1 to 100  {number of lines}
  for j:= 2 to 100 {number of lines again}
    if array[i,x] > array[j,x] then
    begin
      temparray := array[i]  {swap elements via temporary variable}
      array[i] := array[j]
      array[j] := temparray;
    end;

It's the simplest sort there is, also the slowest, but with smallish
arrays takes only a couple of seconds.

Jack.

Quote
Tom Zunder wrote:

> I need to write a very simple application that simply sorts and resorts a
> comma delimited flat file, anyone point me at a simple tutorial URL or a
> book?

> I have Delphi 4, and very low level of Pascal skills!

Other Threads