引用:
原帖由 我要破紀錄 於 28-10-2008 19:16 發表
see this code selection sort
procedure sorting;
begin
i:=1;
while ii do
begin
if markofstudent[j] < markofstudent[j-1] then
begin
temp[j]:=love[j];
love[j]:=love[j-1];
love[j-1] :=temp[j]
...
Use array of records!!

複製內容到剪貼板
代碼:
program CIT_project;
uses wincrt;
const
no_of_std = xxx {<-- you set it}
type
std_data = record {<-- storing data of one student in a systematic way}
ans: string;
marks: integer; {<-- or real}
end;
std_array = array [1..no_of_std] of std_data;
var
std_list: std_array;
procedure Selection_Sort;
var
love : std_data; {<-- a temporary storage of a student data for sorting}
begin
... {Your code here}
end;
Begin {main}
... {Your code here}
End.
How to use records??
- name[j].field
name - the name of the record variable, in this case, std_list
[j] - the loop counter, allows you to sort
field - the field required to do tasks, in this case, mark of ans are possible.
- if the field is omited, the computer will treat the record, not a single field, as a commodity
Assignments syntax
If we want to assign the mark of the first student to be 70 the syntax is:
複製內容到剪貼板
代碼:
std_list[1].mark := 70;
However, for sorting/ swapping two records, the syntax is:
{The type of variable temp is
std_data}
複製內容到剪貼板
代碼:
temp := std_list[j]; {the fields are omitted because we only consider the whole record}
std_list[j] := std_list[j+1];
std_list[j + 1] := temp;
[
本帖最後由 arararchchch 於 2008-10-28 23:36 編輯 ]