I’m working on a sorting program where it takes inputs into an array. I already made Min, Max, and Average. Now I need to do Median, Mode and Sorting (Max to Min, and Min to Max).
Here’s the code I got for sorting [UPDATED New Code]
RichTextBox1.Text = RichTextBox1.Text.Replace(" ", ",")
marks = RichTextBox1.Text.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
Label3.Text = Nothing
Dim z As Integer = marks.Length - 1
Dim y As Integer
Dim TEMP As Integer
For X = 1 To z
For y = 1 To (z - 1)
If marks(y) > marks(y + 1) Then
TEMP = marks(y)
marks(y) = marks(y + 1)
marks(y + 1) = TEMP
End If
Label3.Text = Label3.Text & vbCrLf & marks(y)
Next y
Next X
This is the Selection Sort algorithm from Wikipedia converted to VB.net
Reversing it to do a descending sort should not be difficult, once you’ve fully understood the above.