Bubble Sort not working for repetitive elements
Closed this issue · 1 comments
codehimanshu commented
bubblesort function is not working when there is a repetition of an element in list.
For example when
list = [45,23,76,23,56];
amir734jj commented
Try this instead:
fun bsort [] = []
| bsort [x] = [x]
| bsort (x::y::xs) =
if(y<x) then
y::bsort(x::xs)
else
x::bsort(y::xs);
fun bubblesort [] = []
| bubblesort (x::xs) = bsort(x::(bubblesort(xs)));