Sorting algorithms/Bubble sort: Difference between revisions

(→‎{{header|Scheme}}: Added another example)
Line 130:
Before: +1 +6 +3 +5 +2 +9 +8 +4 +7 +0
After: +0 +1 +2 +3 +4 +5 +6 +7 +8 +9
 
=={{header|AWK}}==
Sort the standard input and print it to standard output.
<lang awk>{ # read every line into an array
line[NR] = $0
}
END { # sort it with bubble sort
do {
haschanged = 0
for(i=1; i < NR; i++) {
if ( line[i] > line[i+1] ) {
t = line[i]
line[i] = line[i+1]
line[i+1] = t
haschanged = 1
}
}
} while ( haschanged == 1 )
# print it
for(i=1; i <= NR; i++) {
print line[i]
}
}</lang>
 
=={{header|BASIC}}==