Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

examples/bubblesort.jl: define the BubbleSort algorithm as an example.

  • Loading branch information...
commit a21784cd51a26746a5a3cecb67151ec939caf85c 1 parent 2c8f9ba
@StefanKarpinski StefanKarpinski authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 examples/bubblesort.jl
View
17 examples/bubblesort.jl
@@ -0,0 +1,17 @@
+importall Base
+
+type BubbleSort <: Sort.Algorithm end
+
+function sort!(::BubbleSort, o::Sort.Ordering, v::AbstractVector, lo::Int, hi::Int)
+ while true
+ clean = true
+ for i = lo:hi-1
+ if Sort.lt(o, v[i+1], v[i])
+ v[i+1], v[i] = v[i], v[i+1]
+ clean = false
+ end
+ end
+ clean && break
+ end
+ return v
+end
Please sign in to comment.
Something went wrong with that request. Please try again.