Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|Icon}}: sample output) |
m (→{{header|Icon}}: note builtins) |
||
Line 655: | Line 655: | ||
=={{header|Icon}}== |
=={{header|Icon}}== |
||
While bubble sort is a basic algorithm it also illustrates a difference in the way Icon handles types. The built-in operators for comparing data types make a syntactic distinction between numeric and string types. Consequently, when writing something like a bubble sort you must (a) write two versions, (b) have the sort figure it out dynamically as in this example. |
While bubble sort is a basic algorithm it also illustrates a difference in the way Icon handles types. The built-in operators for comparing data types make a syntactic distinction between numeric and string types. Consequently, when writing something like a bubble sort you must (a) write two versions, (b) have the sort figure it out dynamically as in this example. In practice this is unnecessary as there are built-in sort functions for basic data types and records. |
||
<lang Icon>procedure bubblesort(X,op) #: simple bubble sort |
<lang Icon>procedure bubblesort(X,op) #: simple bubble sort |
||
local i,sorted |
local i,sorted |