Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Sub Swap(ByRef x As Integer, ByRef y As Integer)
- Dim temp As Integer = x
- x = y
- y = temp
- End Sub
- Sub SortAsc(a() As Integer)
- For i = 0 To a.Length - 2
- For j = i + 1 To a.Length - 1
- If a(i) > a(j) Then
- Swap(a(i), a(j))
- End If
- Next
- Next
- End Sub
- Sub SortDesc(a() As Integer)
- For i = 0 To a.Length - 2
- For j = i + 1 To a.Length - 1
- If a(i) < a(j) Then
- Swap(a(i), a(j))
- End If
- Next
- Next
- End Sub
- Sub SortAsc1(a() As Integer)
- For i = 0 To a.Length - 2
- For j = i + 1 To a.Length - 1
- If MustSwap(a(i), a(j)) Then
- Swap(a(i), a(j))
- End If
- Next
- Next
- End Sub
- Function MustSwap(x As Integer, y As Integer) As Boolean
- Return x > y
- End Function
- Sub Print(a() As Integer)
- For Each v As Integer In a
- Console.WriteLine(v)
- Next
- End Sub
- Sub Main()
- Dim a As Integer = 10
- Dim b As Integer = 20
- Swap(a, b)
- Console.WriteLine("a = {0} b = {1}", a, b)
- Dim array() As Integer = {132, 654, 859, 1234, 90678, 1234, 9}
- Console.WriteLine("Array da ordinare:")
- Print(array)
- Console.WriteLine("Array ordinato in ordine crescente:")
- SortAsc(array)
- Print(array)
- Console.WriteLine("Array ordinato in ordine decrescente:")
- SortDesc(array)
- Print(array)
- Console.WriteLine("Array ordinato secondo quanto decide la funzione MustSwap:")
- SortAsc1(array)
- Print(array)
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement