Algorithm
selection sort in c#
일등하이
2020. 10. 14. 14:14
반응형
stackabuse.com/selection-sort-in-javascript/
Selection Sort in JavaScript
Introduction Selection Sort is one of the simpler and more intuitive sorting algorithms. It is an in-place, unstable, comparison algorithm. This means that it transforms the input collection using no auxiliary data structures and that the input is overridd
stackabuse.com
www.tutorialspoint.com/selection-sort-program-in-chash
Selection Sort program in C#
Selection Sort program in C# Selection Sort is a sorting algorithm that finds the minimum value in the array for each iteration of the loop. Then this minimum value is swapped with the current array element. This procedure is followed until the array is so
www.tutorialspoint.com
using System;
namespace SelectSort {
class Program {
static void Main (string[] args) {
int[] arr = { 4, 1, 5, 3, 2 };
int n = arr.Length;
int smallest;
int temp;
for (int i = 0; i < n - 1; i++) {
smallest = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[smallest]) {
smallest = j;
}
}
temp = arr[smallest];
arr[smallest] = arr[i];
arr[i] = temp;
}
foreach (var num in arr) {
Console.WriteLine (num);
}
}
}
}
반응형