Seal_of_approval

task1(a)

Apr 21st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace task1
  4. {
  5.     class Program
  6.     {
  7.         delegate bool Function<T>(T a, T b);
  8.  
  9.         static bool IntComparator(int a, int b)
  10.         {
  11.             return a > b;
  12.         }
  13.  
  14.         static T[] Sort<T>(T[] a, Function<T> comparator)
  15.         {
  16.             for (int i = 0; i < a.Length - 1; i++)
  17.                 for (int j = i + 1; j < a.Length; j++)
  18.             {
  19.                 if (comparator(a[i], a[j]))
  20.                 {
  21.                     T tmp = a [i];
  22.                     a [i] = a [j];
  23.                     a [j] = tmp;
  24.                 }
  25.             }
  26.             return a;
  27.         }
  28.  
  29.         public static void Main (string[] args)
  30.         {
  31.             int[] arr = {9, 2, 4, 3, 8, 6, 3, 5};
  32.             int[] a = Sort (arr, IntComparator);
  33.  
  34.             for (int i = 0; i < a.Length; i++)
  35.                 Console.Write("{0} ", a[i]);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment