'Visual Basic 2010 Recursie Procedures en Functies Module QuickSort Sub Main() Dim numbers As Integer() = {88, 75, 93, 81, 21, 74, 84, 35} PrintArray(numbers) ' QuickSort(numbers, 0, 7) PrintArray(numbers) ' Console.ReadLine() End Sub Sub PrintArray(ByVal values As Integer()) For Each value As Integer In values Console.Write(value & " ") Next Console.WriteLine() End Sub Sub QuickSort(ByVal array As Integer(), _ ByVal lowerbound As Integer, ByVal upperbound As Integer) Dim count As Integer = upperbound - lowerbound + 1 If count = 2 Then If array(lowerbound) > array(upperbound) Then Dim backup As Integer = array(lowerbound) array(lowerbound) = array(upperbound) array(upperbound) = backup End If ElseIf count > 2 Then Dim pivotIndex As Integer = (lowerbound + upperbound) \ 2 Dim pivot As Integer = array(pivotIndex) ' array(pivotIndex) = array(upperbound) array(upperbound) = pivot ' Dim smallerIndex As Integer = lowerbound Dim biggerIndex As Integer = upperbound ' Do While smallerIndex <> biggerIndex ' Do While array(smallerIndex) <= pivot AndAlso _ smallerIndex < biggerIndex smallerIndex += 1 Loop ' Do While array(biggerIndex) >= pivot AndAlso _ smallerIndex < biggerIndex biggerIndex -= 1 Loop ' If smallerIndex <> biggerIndex Then Dim backup As Integer = array(smallerIndex) array(smallerIndex) = array(biggerIndex) array(biggerIndex) = backup End If Loop ' array(upperbound) = array(biggerIndex) array(biggerIndex) = pivot ' QuickSort(array, lowerbound, biggerIndex - 1) QuickSort(array, smallerIndex + 1, upperbound) End If End Sub End Module 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.