2012-03-18 64 views
2

我有一个项目,程序必须接受10个单词,并按降序(从Z-A的字母顺序) 使用气泡排序显示单词。 以下是我目前所知道的: 程序示例; 使用crt;Pascal Bubble排序

TYPE 
    no._list=ARRAY(1...10)OF REAL; 
CONST 
    no.:no._list=(20.00,50.50.35.70....); 
VAR 
    x:INTEGER; 
    small:REAL; 

BEGIN clrscr: 
    small:=no.(1); 
    FOR x:=2 TO 10 DO 
     IF small>number(x); 
     writeln('Smallest value in the array of no.s is',small:7:2); 
END 

我真的不知道如何做到这一点,但可以使用一些帮助。

+2

你尝试过什么?你有什么具体问题?我们在这里帮助解决问题,而不是为你做功课。 – Corbin 2012-03-18 08:23:02

+0

你知道什么? – Doboy 2012-03-18 08:26:03

+0

哦..对不起..我们的老师只教我们泡泡分类号..这实际上是我们的项目。她实际上并没有讨论这件事,但她把它作为一个项目给了它。 – 2012-03-18 08:26:50

回答

0
function BubbleSort(list: TStringList): TStringList; 
var 
    i, j: Integer; 
    temp: string; 
begin 
    // bubble sort 
    for i := 0 to list.Count - 1 do begin 
    for j := 0 to (list.Count - 1) - i do begin 
     // Condition to handle i=0 & j = 9. j+1 tries to access x[10] which 
     // is not there in zero based array 
     if (j + 1 = list.Count) then 
     continue; 
     if (list.Strings[j] > list.Strings[j+1]) then begin 
     temp    := list.Strings[j]; 
     list.Strings[j] := list.Strings[j+1]; 
     list.Strings[j+1] := temp; 
     end; // endif 
    end; // endwhile 
    end; // endwhile 
    Result := list; 
end;