Selection Sort using array in .NET
This resource is about selection sorting which is one of the sorting techniques.In this elements are taken at run time from the user and then they are sorting in ascending order and displayed in sorted order.
In this program,
1. User enters the number of terms he/she needs to sort
2. Enters the elements to be sorted
3. Gets the elements in sorted order
Private Sub SelectionSort()
Dim intArray(50) As Integer
Dim i, j, pos, min, n As Integer
Dim strOutput As String = ""
Console.Write("Program of Selection Sort")
Console.WriteLine("Enter number of terms to be entered:-")
n = Console.ReadLine
'Creating a matrix
For i = 0 To n - 1
Console.Write("Enter any value")
intArray(i) = Console.ReadLine
Next
For i = 0 To n - 1
pos = i
min = intArray(i)
For j = i + 1 To n - 1
If intArray(j) < intArray(pos) Then
pos = j
min = intArray(j)
End If
Next
intArray(pos) = intArray(i)
intArray(i) = min
Next
'The final output is saved in variable strOutput.
For i = 0 To n - 1
If strOutput.Length = 0 Then
strOutput = intArray(i)
Else
strOutput = strOutput & "," & intArray(i)
End If
Next
Console.WriteLine(strOutput)
End Sub