0% found this document useful (0 votes)
43 views1 page

Código Delphi

The document provides code samples for bubble sorting arrays and TStringLists in Delphi. The array bubble sort code uses a nested for loop to iterate through the array and swap adjacent elements if out of order. The TStringList bubble sort code similarly uses nested for loops to iterate through the list and swap adjacent strings if alphabetically out of order, returning the sorted list.

Uploaded by

Derly Velasquez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Código Delphi

The document provides code samples for bubble sorting arrays and TStringLists in Delphi. The array bubble sort code uses a nested for loop to iterate through the array and swap adjacent elements if out of order. The TStringList bubble sort code similarly uses nested for loops to iterate through the list and swap adjacent strings if alphabetically out of order, returning the sorted list.

Uploaded by

Derly Velasquez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Cdigo Delphi [-] procedure TBubbleSort.

Sort(var A: array of Integer); var I, J, T: Integer; begin for I := High(A) downto Low(A) do for J := Low(A) to High(A) - 1 do if A[J] > A[J + 1] then begin VisualSwap(A[J], A[J + 1], J, J + 1); T := A[J]; A[J] := A[J + 1]; A[J + 1] := T; if Terminated then Exit; end; end;

Para un TStringList:
Cdigo Delphi [-] 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;

You might also like