El 05/09/2010 18:31, Dilwyn Jones escribió:
(This is a Quanta helpline query!)

Does anyone have a handy little merge sort routine (in s*basic), to
merge two sorted lists (plain text word lists), maintaining the sorted
order in the output file.

That is, merge file A and file B (both already sorted) and output as
file C (also sorted, containing both files A and B merged).

It's a very common routine. This is not SuperBASIC, but it may help you:

Open file A input
Open file B input
Open file C output

Read line from A into L1
Read line from B into L2

Repeat
  If L1<L2 then
    While L1<L2 and not eof(A)
      Write line from L1 into C
      Read line from A into L1
    End While
    If eof(A)
      Write remaining lines of B into C
    End If
  Else If L2<=L1 then
    While L2<=L1 and not eof(B)
      Write line from L2 into C
      Read line from B into L2
    End While
    If eof(B)
      Write remaining lines of A into C
    End If
  End If
Until eof(A) and eof(B)

Close A
Close B
Close C

_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to