コード例 #1
0
        static void Main(string[] args)
        {
            IComparer revComparer = new ReverseStringComparer();
            IComparer comparer    = new StringComparer();

            String[] words = { "The",  "QUICK", "BROWN", "FOX", "jumps",
                               "over", "the",   "lazy",  "dog", "Hiearahy","Hiccap", "HILLS" };

            // set basic culture to ru-RU
            Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");

            Array.Sort(words);
            Console.WriteLine("After sorting the entire array by using the default comparer:");
            DisplayValues(words);

            Array.Sort(words, comparer);
            Console.WriteLine("After sorting the entire array by using My string comparer:");
            DisplayValues(words);

            Array.Sort(words, revComparer);
            Console.WriteLine("After sorting the entire array using the My String reverse comparer:");
            DisplayValues(words);

            // Change Culture
            Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
            Console.WriteLine("In Turkey language");
            //reset previous sorting
            words = new String[] { "The", "QUICK", "BROWN", "FOX", "jumps",
                                   "over", "the", "lazy", "dog", "Hiearahy", "Hiccap", "HILLS" };


            Array.Sort(words);
            Console.WriteLine("TR After sorting the entire array by using the default comparer:");
            DisplayValues(words);

            Array.Sort(words, comparer);
            Console.WriteLine("TR After sorting the entire array by using My stringcomparer:");
            DisplayValues(words);

            Array.Sort(words, revComparer);
            Console.WriteLine("TR After sorting the entire array using the My reverse string comparer:");
            DisplayValues(words);


            Console.ReadKey();
        }
コード例 #2
0
ファイル: Demo.cs プロジェクト: ker2x/drakon
 private static void quicksortDemo()
 {
     // item 62
     Console.WriteLine("quick sort demo");
     // item 58
     Object[] unsorted = new Object[] { "the", "sooner", "we", "start", "this", "the", "better" };
     Object[] sorted   = new Object[] { "aa", "bb", "cc", "dd", "ee", "ff" };
     Object[] reverse  = new Object[] { "ff", "ee", "dd", "cc", "bb", "aa" };
     Object[] empty    = new Object[] {};
     Object[] flat     = new Object[] { "flat", "flat", "flat", "flat", "flat" };
     // item 59
     IComparer<Object> comparer = new ReverseStringComparer();
     Sorter.quicksort(comparer, unsorted, 0, unsorted.Length);
     Sorter.quicksort(comparer, sorted, 0, sorted.Length);
     Sorter.quicksort(comparer, reverse, 0, reverse.Length);
     Sorter.quicksort(comparer, empty, 0, empty.Length);
     Sorter.quicksort(comparer, flat, 0, flat.Length);
     // item 60
     print(unsorted);
     print(sorted);
     print(reverse);
     print(empty);
     print(flat);
     // item 61
     stringsAreSorted(unsorted);
     stringsAreSorted(sorted);
     stringsAreSorted(reverse);
     stringsAreSorted(empty);
     stringsAreSorted(flat);
     // item 65
     Console.WriteLine();
 }
コード例 #3
0
ファイル: Demo.cs プロジェクト: GastonDac/drakon_editor
 private static void QuicksortDemo()
 {
     // item 62
     Console.WriteLine("quick sort demo");
     // item 58
     var unsorted = new Object[] { "the", "sooner", "we", "start", "this", "the", "better" };
     var sorted   = new Object[] { "aa", "bb", "cc", "dd", "ee", "ff" };
     var reverse  = new Object[] { "ff", "ee", "dd", "cc", "bb", "aa" };
     var empty    = new Object[] {};
     var flat     = new Object[] { "flat", "flat", "flat", "flat", "flat" };
     // item 59
     IComparer<Object> comparer = new ReverseStringComparer();
     // item 198
     Sort(unsorted, comparer);
     Sort(sorted, comparer);
     Sort(reverse, comparer);
     Sort(empty, comparer);
     Sort(flat, comparer);
     // item 60
     Print(unsorted);
     Print(sorted);
     Print(reverse);
     Print(empty);
     Print(flat);
     // item 61
     StringsAreSorted(unsorted);
     StringsAreSorted(sorted);
     StringsAreSorted(reverse);
     StringsAreSorted(empty);
     StringsAreSorted(flat);
     // item 65
     Console.WriteLine();
 }