https://www.youtube.com/watch?v=4kKa7qxd4cc&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DulAlgorithm
{
class Algorithm
{
public static int[] SelectionSort(int[] numbers)
{
// [1] Input
int N = numbers.Length;
// [2] Process
for(int i = 0; i < N - 1; i++)
{
for(int j = i + 1; j < N; j++) // 부등호 방향 : 오름차순(>), 내림차순(<)
{
if(numbers[i] > numbers[j])
{
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
// [3] Output
return numbers;
}
}
}
using System;
namespace DulAlgorithm.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// [1] Input
int[] data = { 1, 4, 3, 2, 5 };
// [2] Process
int[] numbers = DulAlgorithm.Class1.SelectionSort(data);
// [3] Output
foreach(int number in numbers)
{
Console.WriteLine(number);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DulAlgorithm.WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// [1] Input
int[] data = { 1, 4, 3, 2, 5 };
// [2] Process
int[] numbers = DulAlgorithm.Algorithm.SelectionSort(data);
// [3] Output
MessageBox.Show(numbers[1].ToString());
}
}
}