推介:| UGG | baby product | MD skinical | 環保袋訂造 | PROTOP | 鈙利亞阿勒頗手工古皂 | UGG Boots | Sheepskin Boots |

發新話題
打印

pascal 極不可能的問題,哭求大家!!!!!!!!

pascal 極不可能的問題,哭求大家!!!!!!!!

see this code  selection sort
procedure sorting;
begin
i:=1;
while i<36 do
begin
j:=36;
while j>i do
begin
if markofstudent[j] < markofstudent[j-1] then
begin
temp[j]:=love[j];
love[j]:=love[j-1];
love[j-1] :=temp[j]
end;
j:=j-1
end;
i:=i+1
end;
for i:= 1 to 36 do
writeln(love,'')

而家個love(string) array 同markofstudent(integer) array d 野一樣,
love save 左分 (string)  markofstudent都係save左分(integer)
why write出尼唔係全部咁sort ,係2學生個2個學生咁sort,why?

TOP

引用:
原帖由 我要破紀錄 於 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 編輯 ]

TOP

thx you thx you

TOP

引用:
原帖由 我要破紀錄 於 29-10-2008 20:24 發表
thx you thx you
Does the code work?

TOP

我唔用record 用返我的方法why唔得?

TOP

引用:
原帖由 我要破紀錄 於 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 編輯 ]

TOP

回復 5# 的帖子

1.  小弟相信閣下用love的string array去儲存名字, 而
     markofstudent則是對應的integer array去儲存積分
2.  那麼, 在sorting內, 閣下要根據
      markofstudent[j] < markofstudent[j-1]
      把love及markofstudent同時swap
IT代工/鎗手一名!
小弟並唔平, 但絕唔係貴!

TOP

引用:
原帖由 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

TOP

jayzhou is good

TOP

引用:
原帖由 我要破紀錄 於 3-11-2008 22:24 發表
jayzhou is good
版主始終係版主...

恕小弟班門弄斧...

TOP

發新話題


重要聲明:本討論區是以即時上載留言的方式運作,本網站對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。本討論區有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。


Copyright 1997- Xocat. All Right Reserved.