Guest User

Untitled

a guest
Oct 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Dim x As Integer = 10
  2. Dim numArrray(x - 1) As Integer
  3.  
  4. For i = 0 To x - 1
  5. Randomize()
  6. numArrray(i) = CInt(Rnd() * 9)
  7. Next
  8.  
  9. Quicksort(numArrray, 0, numArrray.Length - 1)
  10.  
  11. For i = 0 To x - 1
  12. Console.Write(numArrray(i))
  13. Next
  14. Console.ReadLine()
  15. End Sub
  16.  
  17. Sub Quicksort(ByVal array() As Integer, ByVal min As Integer, ByVal max As Integer)
  18. Dim pivot As Integer
  19.  
  20. If min < max Then
  21. pivot = partition(array, min, max)
  22. Quicksort(array, min, pivot - 1)
  23. Quicksort(array, pivot + 1, max)
  24. End If
  25. End Sub
  26.  
  27. Function partition(ByVal array() As Integer, ByVal min As Integer, ByVal max As Integer) As Integer
  28. Dim pivot As Integer = array(max)
  29. Dim count As Integer = min - 1
  30. Dim placeholder As Integer
  31.  
  32. For i = min To max - 1
  33. If array(i) < pivot Then
  34. count += 1
  35. placeholder = array(count)
  36. array(count) = array(i)
  37. array(i) = placeholder
  38. End If
  39. Next
  40. If array(max) < array(count + 1) Then
  41. placeholder = array(count + 1)
  42. array(count + 1) = array(max)
  43. array(max) = placeholder
  44. End If
  45. Return count
  46.  
  47. End Function
Add Comment
Please, Sign In to add comment