Permalink
Browse files

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

  • Loading branch information...
StefanKarpinski committed Feb 2, 2013
1 parent 2c8f9ba commit a21784cd51a26746a5a3cecb67151ec939caf85c
Showing with 17 additions and 0 deletions.
  1. +17 −0 examples/bubblesort.jl
View
@@ -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

0 comments on commit a21784c

Please sign in to comment.