Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace task1
- {
- class Program
- {
- delegate bool Function<T>(T a, T b);
- static bool IntComparator(int a, int b)
- {
- return a > b;
- }
- static T[] Sort<T>(T[] a, Function<T> comparator)
- {
- for (int i = 0; i < a.Length - 1; i++)
- for (int j = i + 1; j < a.Length; j++)
- {
- if (comparator(a[i], a[j]))
- {
- T tmp = a [i];
- a [i] = a [j];
- a [j] = tmp;
- }
- }
- return a;
- }
- public static void Main (string[] args)
- {
- int[] arr = {9, 2, 4, 3, 8, 6, 3, 5};
- int[] a = Sort (arr, IntComparator);
- for (int i = 0; i < a.Length; i++)
- Console.Write("{0} ", a[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment