Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim x As Integer = 10
- Dim numArrray(x - 1) As Integer
- For i = 0 To x - 1
- Randomize()
- numArrray(i) = CInt(Rnd() * 9)
- Next
- Quicksort(numArrray, 0, numArrray.Length - 1)
- For i = 0 To x - 1
- Console.Write(numArrray(i))
- Next
- Console.ReadLine()
- End Sub
- Sub Quicksort(ByVal array() As Integer, ByVal min As Integer, ByVal max As Integer)
- Dim pivot As Integer
- If min < max Then
- pivot = partition(array, min, max)
- Quicksort(array, min, pivot - 1)
- Quicksort(array, pivot + 1, max)
- End If
- End Sub
- Function partition(ByVal array() As Integer, ByVal min As Integer, ByVal max As Integer) As Integer
- Dim pivot As Integer = array(max)
- Dim count As Integer = min - 1
- Dim placeholder As Integer
- For i = min To max - 1
- If array(i) < pivot Then
- count += 1
- placeholder = array(count)
- array(count) = array(i)
- array(i) = placeholder
- End If
- Next
- If array(max) < array(count + 1) Then
- placeholder = array(count + 1)
- array(count + 1) = array(max)
- array(max) = placeholder
- End If
- Return count
- End Function
Add Comment
Please, Sign In to add comment