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

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
intArray(pos) = intArray(i)
intArray(i) = min

'The final output is saved in variable strOutput.
For i = 0 To n - 1
If strOutput.Length = 0 Then
strOutput = intArray(i)
strOutput = strOutput & "," & intArray(i)
End If
End Sub


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: