Hi, I'm just starting out in programming and I'm currently making a small program which shows how Bubble, selection and Insertion sorts work. I've found a small program which bubble sorts a user selected number of integers and shows each step at which these are sorted (each pass). However this program doesn't sort the way a bubble sort should work (eg the largest element should be at the last index on the first pass).
I'm in the middle of altering the source code, this is what it was originally:
Private Sub Command1_Click() For x = 1 To UBound(myArr) - 1 For y = (x + 1) To UBound(myArr) If myArr(x) >= myArr(y) Then doSwap x, y End If Next y Next x End Sub
you can see that if the first element isn't bigger then the second it will increment only y so if the first elemnt is bigger then the third the first and third will switch positions (like a selection sort).
I want the code to look something like this:
Private Sub cmdSort_Click() For x = 1 To UBound(Sarray) - 1 For y = (x + 1) To UBound(Sarray) If Sarray(x) >= Sarray(y) Then doSwap x, y Else increment y increment x End If End Sub
so that if the first element is smaller then the second, the first element stays in current position and then the second elemnt is compared to the third. Bust since I'm only new to programming i have no idea what to type.
Help is appreciated. Thank you.