My algorithm is not working, I’m a newbie to all algorithms and javascript and I just can’t seem to work out why it’s not working.
Here’s the Array (23, 19, 35, 12, 30)
Max value = 0
Here’s what I have…
For K= 0 to n – 2
MAX = 0
For j = 0 to n – k - 2
If item[j] > item[MAX]
MAX = item[j]
end if
end for
swap n - k - 2 with item[MAX]
end for
end SelectionSort
Where have I gone wrong? thanks!!!!
Also, if anyone could tell me how to use it in a trace table I would be sooo happy!
Kind regards
Craig
Using max in this expression is causing the problem item[MAX], It would be j. Please give it a consideration and then try again like this, The selection sort Demo