Files
dotNetAdvcdGrammer/Delegate/InterB.cs
2022-07-12 16:43:56 +09:00

49 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Delegate
{
class InterB
{
public delegate int CompareDelegate(int i1, int i2);
public static void Sort(int[] arr, CompareDelegate comp)
{
if (arr.Length < 2)
return;
Console.WriteLine("함수 Prototype: " + comp.Method);
int ret;
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
ret = comp(arr[i], arr[j]);
if (ret == -1)
{
int tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
Show(arr);
}
private static void Show(int[] arr)
{
foreach (int i in arr)
{
Console.WriteLine(i + " ");
}
Console.WriteLine();
}
}
}