amir734jj/SML-NJ-sorting-algorithms

Bubble Sort not working for repetitive elements

Closed this issue · 1 comments

bubblesort function is not working when there is a repetition of an element in list.
For example when
list = [45,23,76,23,56];

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)));