Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- namespace task
- {
- public class Service <T>
- {
- private List<T> list;
- private Function comparator;
- private event EventHandler end_Sort;
- public delegate void EventHandler (List <T> list);
- public delegate int Function (T a, T b);
- public Service (List <T> list, Function comparator)
- {
- this.list = list;
- this.comparator = comparator;
- }
- public void Runner ()
- {
- Thread th1 = new Thread (delegate() {
- list.Sort (new Comparison <T> (comparator));
- if (end_Sort != null)
- end_Sort (list);
- });
- th1.Start ();
- }
- public void AddHandler (EventHandler handler)
- {
- end_Sort += handler;
- }
- }
- class Program
- {
- public static int IntComparator(int a, int b)
- {
- return a.CompareTo(b);
- }
- public static void Print<T>(List<T> list)
- {
- foreach (var item in list)
- Console.Write("{0} ", item);
- }
- public static void Main(string[] args)
- {
- List<int> list = new List<int> { 9, 2, 4, 3, 8, 6, 3, 5 };
- List<int> array = new List<int> { 9, 8, 7, 6, 5, 4, 3, 2 };
- Service<int> intServ = new Service<int> (list, IntComparator);
- intServ.AddHandler (Print<int>);
- intServ.Runner ();
- Thread.Sleep (300);
- Console.WriteLine ();
- Service<int> intServ_a = new Service<int> (array, IntComparator);
- intServ_a.AddHandler (Print<int>);
- intServ_a.Runner ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment