This message was edited by iby at 2002-9-26 13:16:41
: Your unit has destroyed my pascal:
: I wrote to it Clrscr and i've got an error and now every time when Im open the pascal I can't see a thing... Please help.
: P.S.
: sorry about my english
:
Well, first of all, only TP7 has faulty CRT unit,
if I'm not mistaken. You mentioned that you have TP6.
If so and you have copied CRT.TPU to your pascal
directory, simply remove it.
If the CRT.TPU is part of the TURBO.TPL, replace this
file with original (the one that comes with your pascal version).
Now back to your array question. It looks to me that
you want to sort array A[] and place it into B[].
Try any sorting algorythm you can find.
As always the simplest one is not the fastest.
There are always compromises. I hope you will
find following code simple enough:
program sort_test;
var ArrayA,ArrayB:array[1..10] of integer;
i,j,temp:integer;
begin
{ Get some numbers from user }
for i:=1 to 10 do
begin
write('Enter integer nr.',i,': ');
readln(ArrayA[i]);
end;
{ Copy values to ArrayB }
ArrayB:=ArrayA;
{ Sort the values of ArrayB. This is not quite straight
forward, but here is an explanation:
Assume first array element is the smallest. Often, this is
not true but we have to start somewhere and there are
worse choices than starting from begining...
Now, search through array and see if we find element that
is even smaller and replace it with the one we tought it
was the smallest.
This way size of array doesn't change, only thing that
happened was that smallest element got to first place,
and one that was there before is moved back to it's place.
So very first element is ok. To sort the rest of the array
you have to keep repeating the process untill end of the array
is reached. }
{ note: index "i" points to what we think is the smallest element.
index "j" points to other elements we are screening }
for i:=1 to 9 do
for j:=i+1 to 10 do
{ check if found element is smaller }
if ArrayB[j]<ArrayB[i] then
{ if smaller, swap the elements }
begin
temp:=ArrayB[j];
ArrayB[j]:=ArrayB[i];
ArrayB[i]:=temp;
end;
{ print both arrays for comparison }
writeln('A B');
writeln('----------------');
for i:=1 to 10 do
writeln(ArrayA[i],' ',ArrayB[i]);
writeln('Check if Array B is sorted. Press Enter to exit...');
readln;
end.
Iby
2B ?
----| |----+----------( )--
|
2B |
----|/|----+