,'')
而家個love(string) array 同markofstudent(integer) array d 野一樣,
love save 左分 (string) markofstudent都係save左分(integer)
why write出尼唔係全部咁sort ,係2學生個2個學生咁sort,why?
作者: arararchchch 時間: 2008-10-28 22:52
引用:
原帖由 我要破紀錄 於 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 編輯 ]
作者: 我要破紀錄 時間: 2008-10-29 20:24
thx you thx you
作者: arararchchch 時間: 2008-10-29 23:20
引用:
原帖由 我要破紀錄 於 29-10-2008 20:24 發表 
thx you thx you
Does the code work?
作者: 我要破紀錄 時間: 2008-10-30 19:51
我唔用record 用返我的方法why唔得?
作者: arararchchch 時間: 2008-10-30 22:11
引用:
原帖由 我要破紀錄 於 30-10-2008 19:51 發表 
我唔用record 用返我的方法why唔得?
It's OK, but record is more easy to organize and use...
Otherwise, you have to use parallel arrays...
Good luck!!
[ 本帖最後由 arararchchch 於 2008-10-31 18:16 編輯 ]
作者: jayzhou_2046 時間: 2008-10-31 23:12 標題: 回復 5# 的帖子
1. 小弟相信閣下用love的string array去儲存名字, 而
markofstudent則是對應的integer array去儲存積分
2. 那麼, 在sorting內, 閣下要根據
markofstudent[j] < markofstudent[j-1]
把love及markofstudent同時swap
作者: arararchchch 時間: 2008-11-1 10:48
引用:
原帖由 jayzhou_2046 於 31-10-2008 23:12 發表 
1. 小弟相信閣下用love的string array去儲存名字, 而
markofstudent則是對應的integer array去儲存積分
2. 那麼, 在sorting內, 閣下要根據
markofstudent[j] < markofstudent[j-1]
把love及m ...
補充一下
2.為Parallel arrays
作者: 我要破紀錄 時間: 2008-11-3 22:24
jayzhou is good
作者: arararchchch 時間: 2008-11-3 23:12
引用:
原帖由 我要破紀錄 於 3-11-2008 22:24 發表 
jayzhou is good
版主始終係版主...
恕小弟班門弄斧...
歡迎光臨 香港 Xocat Forum 討論區 (http://p.xocat.com/p/) |
Powered by Discuz! 6.0.0 |