Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
m
AWK example update: Customarily arrays in Awk start with index 1, not index 0
(→{{header|AWK}}: Fix markup) |
m (AWK example update: Customarily arrays in Awk start with index 1, not index 0) |
||
Line 218:
}</lang>
GNU awk contains built in sort() functions, but for POSIX
here is a simple
is not possible to return arrays from
array is "edited in place". The extra parameters passed in
function's argument
variables.
<lang awk>
# Test this example file from command line with:
#
# awk -f file.awk /dev/null
#
# Code by Jari Aalto <jari.aalto A T cante net>
# Licensed and released under GPL-2+, see http://spdx.org/licenses
function alen(array, dummy, len) {
for (dummy in array)
len++;
return len;
}
Line 244 ⟶ 249:
haschanged = 0
for (i =
{
if (
{
tmp = array[i]
array[i] = array[i + 1]
array[i + 1] = tmp
haschanged = 1
}
Line 257 ⟶ 262:
}
# An Example. Sorts array to order: b, c, z
{
array[
array[
array[
sort(array)
print array[
exit
}
|