Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
No edit summary
Line 3,745: Line 3,745:
{{works with|Delphi|6.0}}
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
{{libheader|SysUtils,StdCtrls}}
This quick sort routine is infinitely versatile. It sorts an array of pointers. The advantage of this is that pointers can contain anything, ranging from integers, to strings, to floating point numbers to objects. The way each pointer is interpreted through the compare routine, which is customized for the particular situation. The compare routine can interpret each pointer as a string, integer, float or object and it can treat those items in different ways. For example, the order in which it compares strings controls wether the sort is alphabetical or reverse alphabetical. In this case, I show an integer sort, an alphabetic string sort, a reverse alphbetical string sort and a string sort by length.
This quick sort routine is infinitely versatile. It sorts an array of pointers. The advantage of this is that pointers can contain anything, ranging from integers, to strings, to floating point numbers to objects. The way each pointer is interpreted is through the compare routine, which is customized for the particular situation. The compare routine can interpret each pointer as a string, an integer, a float or an object and it can treat those items in different ways. For example, the order in which it compares strings controls whether the sort is alphabetical or reverse alphabetical. In this case, I show an integer sort, an alphabetic string sort, a reverse alphabetical string sort and a string sort by length.


<syntaxhighlight lang="Delphi">
<syntaxhighlight lang="Delphi">
Line 3,916: Line 3,916:


</pre>
</pre>



=={{header|Dart}}==
=={{header|Dart}}==