Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace @delegate
- {
- class TestArray <T>
- {
- private T[] array;
- public TestArray( T [] _array)
- {
- //array = new T[_array.Length];
- //for (int i = 0; i < _array.Length; i++)
- //{
- // array[i] = _array[i];
- //}
- array = _array;
- }
- public delegate int Compare( T first, T second);
- public void Compares(Compare Comp)
- {
- T t;
- for (int i = 0; i < array.Length; ++i)
- for(int j = 0; j < array.Length - i -1; j ++)
- {
- if(Comp(array[j], array[j+1]) == 1)
- {
- t = array[j];
- array[j] = array[j + 1];
- array[j+1] = t;
- }
- }
- }
- public delegate void EventHandler();
- public event EventHandler message;
- //private void OnAnotherDecade(int decade)
- //{
- // if (AnotherDecade != null)
- // {
- // AnotherDecade(this, new TestDecadeEventArgs(decade));
- // }
- //}
- public void Sort(Compare comp)
- {
- //int decimalCounter = 0;
- Compares(comp);
- message();
- //for (int i = 0; i < array.Length; i++)
- //{
- // Console.WriteLine(array[i]);
- // decimalCounter++;
- // if (decimalCounter >= 10)
- // {
- // decimalCounter = 0;
- // OnAnotherDecade(i / 10);
- // }
- // Thread.Sleep(TimeSpan.FromMilliseconds(300));
- //}
- }
- public void Print()
- {
- foreach(T i in array)
- Console.WriteLine("{0}", i);
- }
- }
- //public class TestDecadeEventArgs : EventArgs
- // {
- // public int Decade { get; private set; }
- // public TestDecadeEventArgs(int decade)
- // {
- // Decade = decade;
- // }
- // }
- class Programm
- {
- private static void Message()
- {
- Console.WriteLine("Array is sorted");
- }
- public static int CompareString(string x, string y)
- {
- if (x.Length < y.Length) return -1;
- else if (x.Length > y.Length) return 1;
- else return string.Compare(x, y);
- }
- public static int CompareInt(int x, int y)
- {
- if (x > y) return 1;
- else if (x == y) return 0;
- else return -1;
- }
- public static int CompareDouble(double x, double y)
- {
- if (x > y) return 1;
- else if (x == y) return 0;
- else return -1;
- }
- static void Main(string[] args)
- {
- string[] str1 = { "as", "absd", "hello", "say", "abbb", "conclusion", "cat", "story", "factory", "advance", "cold", "ice", "touch" };
- string[] str2 = { "cover", "mussle", "boullet", "house", "horse", "statisfaction", "moon", "black", "night", "middle", "contry" };
- int[] int1 = { 12, 13, 21, 32, -2, 5, 19, 40 };
- double[] doub1 = { 123.4, 12, 432, 65, 213.33, 232.76, 654.9 };
- TestArray<string> arr1 = new TestArray<string>(str1);
- TestArray<int> arr3 = new TestArray<int>(int1);
- TestArray<string> arr4 = new TestArray<string>(str2);
- arr1.message += Message;
- arr1.Sort(CompareString);
- arr1.Print();
- Console.WriteLine();
- arr3.message += Message;
- arr3.Sort(CompareInt);
- arr3.Print();
- Console.WriteLine();
- arr4.message += Message;
- arr4.Sort(CompareString);
- arr4.Print();
- //Thread th1 = new Thread(arr1.Run(CompareString));
- //th1.Start(CompareString);
- //Thread th2 = new Thread(arr4.Run);
- //th2.Start(CompareString);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement