home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 92
/
af092a.adf
/
af92.lzx
/
ARexx_Code
/
bubble_sort.rexx
next >
Wrap
OS/2 REXX Batch file
|
1996-10-30
|
2KB
|
103 lines
/* ---------------------------------------------- */
/* bubble_sort.rexx - sorts the words in a text file into order */
word.=''; total_count=0
/* ---------------------------------------------- */
/* first step is to read all lines from the file and
place words into the word. compound variable set... */
say "enter source filename and path?"; pull source_name
say "enter destination filename and path?"; pull dest_name
if Open(s,source_name,'r') then
do
if Open(d,dest_name,'w') then
do
do while ~EOF(s)
text=Readln(s)
count=Words(text)
if count>0 then
do
do i=1 to count
j=total_count+i
word.j=Word(text,i)
end
total_count=total_count+count
end
end
/* now we bubble sort... */
do i=total_count to 1 by -1
do j=2 to i
x=j-1
if Upper(word.x)>Upper(word.j) then
do
temp=word.x
word.x=word.j
word.j=temp
end
end
end
/* now write data and close files before exiting... */
do i=1 to total_count
call Writeln(d,word.i)
end
Close(d)
say 'Function complete!'
end
else say 'Sorry - cannot open destination file!'
Close(s)
end
else say 'Sorry - cannot open source file!'
exit
/* ---------------------------------------------- */