当前位置: 首页>>代码示例>>C#>>正文


C# SortableCollection.Shuffle方法代码示例

本文整理汇总了C#中SortableCollection.Shuffle方法的典型用法代码示例。如果您正苦于以下问题:C# SortableCollection.Shuffle方法的具体用法?C# SortableCollection.Shuffle怎么用?C# SortableCollection.Shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortableCollection的用法示例。


在下文中一共展示了SortableCollection.Shuffle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("Quicksorter result:");
            collection.Sort(new QuickSorter<int>());
            collection.PrintAllItemsOnConsole();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101) + Environment.NewLine);

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101) + Environment.NewLine);

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:34,代码来源:Program.cs

示例2: Main

    static void Main()
    {
        var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
        Console.WriteLine("All items before sorting:");
        Console.WriteLine(collection);

        Console.WriteLine("SelectionSorter result:");
        collection.Sort(new SelectionSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Quicksorter result:");
        collection.Sort(new Quicksorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("MergeSorter result:");
        collection.Sort(new MergeSorter<int>());
        Console.WriteLine(collection);

        Console.WriteLine("Linear search 101:");
        Console.WriteLine(collection.LinearSearch(101));

        Console.WriteLine("Binary search 101:");
        Console.WriteLine(collection.BinarySearch(101));

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        Console.WriteLine(collection);

        Console.WriteLine("Shuffle again:");
        collection.Shuffle();
        Console.WriteLine(collection);
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:32,代码来源:Program.cs

示例3: Main

        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, -2, 300, 11, 55, 33, 10, -15, 88, 101, 33, 0, 101, 44, 33 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, -2, 300, 11, 55, 33, 10, -15, 88, 101, 33, 0, 101, 44, 33 });
            Console.WriteLine("Quicksorter result:");
            var quickSorter = new Quicksorter<int>();
            collection.Sort(quickSorter);
            quickSorter.PrintResults();
            //collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, -2, 300, 11, 55, 33, 10, -15, 88, 101, 33, 0, 101, 44, 33 });
            Console.WriteLine("MergeSorter result:");
            var mergeSort = new MergeSorter<int>();
            collection.Sort(mergeSort);
            mergeSort.ShowResults();
            //collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            collection = new SortableCollection<int>(new int[20]);
            for (int i = 1; i <= 20; i++)
            {
                collection.Items[i - 1] = i;
            }
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
开发者ID:Boyan1912,项目名称:Data-Structures-And-Algorithms,代码行数:52,代码来源:Program.cs

示例4: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);
            collectionToSort.Sort(new BucketSorter { Max = MaxValue });

            Console.WriteLine(collectionToSort);

            var collectionToShuffle = new SortableCollection<int>(1, 2, 3, 4, 5);
            Console.WriteLine("Before shufflin` " + collectionToShuffle);
            collectionToShuffle.Shuffle();
            Console.WriteLine("After shufflin` " + collectionToShuffle);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            // collection.Sort(new Quicksorter<int>());
            collection.Sort(new InsertionSorter<int>());
            Console.WriteLine(collection);
        }
开发者ID:aanguelov,项目名称:AlgorithmsHomeworks,代码行数:29,代码来源:SortableCollectionPlayground.cs

示例5: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 22;
            const int MaxValue = 150;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            var collectionToSort = new SortableCollection<int>(array);

            collectionToSort.Sort(new BucketSorter { Max = MaxValue });
            Console.WriteLine(collectionToSort);

            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            collection = new SortableCollection<int>(3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48);
            Console.WriteLine(collection);

            collection.Shuffle();
            Console.WriteLine(collection);

            //collection.Sort(new Quicksorter<int>());
            //Console.WriteLine(collection);
        }
开发者ID:ttitto,项目名称:DataStructuresAndAlgorithms,代码行数:27,代码来源:SortableCollectionPlayground.cs

示例6: Main

        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            ///
            /// Uncomment the sort you want to see and leave
            /// others commented
            ///

            //Console.WriteLine("SelectionSorter result:");
            //collection.Sort(new SelectionSorter<int>());
            //collection.PrintAllItemsOnConsole();
            //Console.WriteLine();

            Console.WriteLine("Quicksorter result:");
            collection.Sort(new Quicksorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            //Console.WriteLine("MergeSorter result:");
            //collection.Sort(new MergeSorter<int>());
            //collection.PrintAllItemsOnConsole();
            //Console.WriteLine();




            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:47,代码来源:Program.cs

示例7: Main

        public static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            Console.WriteLine("Unshuffled");
            Console.WriteLine(string.Join(", ", collection));

            collection.Shuffle();

            Console.WriteLine("Shuffled");
            Console.WriteLine(string.Join(", ", collection));

            collection.Shuffle();

            Console.WriteLine("Shuffled");
            Console.WriteLine(string.Join(", ", collection));
        }
开发者ID:iliankostov,项目名称:Algorithms,代码行数:17,代码来源:SortableCollectionPlayground.cs

示例8: Main

        internal static void Main()
        {
            var collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("QuickSorter result:");
            collection.Sort(new QuickSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Linear search 101:");
            Console.WriteLine(collection.LinearSearch(101));
            Console.WriteLine();

            Console.WriteLine("Binary search 101:");
            Console.WriteLine(collection.BinarySearch(101));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Test sort performance:");
            PerformanceTester.Test(new SelectionSorter<int>(), new QuickSorter<int>(), new MergeSorter<int>());
        }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:45,代码来源:Program.cs

示例9: Main

        public static void Main()
        {
            List<int> numbers = new List<int>() { 1,2,4,5,67,87,2,1,2,4,5,6,7,54,8 };
            SortableCollection<int> sortableCollection = new SortableCollection<int>(numbers);

            List<int> shuffledNumbers = new List<int>(sortableCollection.Shuffle());

            Console.WriteLine(string.Join(",", shuffledNumbers));
        }
开发者ID:hristo-iliev,项目名称:TelerikHW,代码行数:9,代码来源:Shuffle.cs

示例10: Main

        public static void Main(string[] args)
        {
            const int NumberOfElementsToSort = 100;
            const int MaxValue = 999;

            var array = new int[NumberOfElementsToSort];

            for (int i = 0; i < NumberOfElementsToSort; i++)
            {
                array[i] = Random.Next(MaxValue);
            }

            Console.WriteLine("Sort:");
            var collectionToSort = new SortableCollection<int>(array);
            collectionToSort.Sort(new BucketSorter { Max = MaxValue });
            Console.WriteLine(collectionToSort);
            Console.WriteLine("Shuffle:");
            collectionToSort.Shuffle();
            Console.WriteLine(collectionToSort);
            
            Console.WriteLine();
            Console.WriteLine("New collection:");
            var collection = new SortableCollection<int>(2, -1, 5, 0, -3);
            Console.WriteLine(collection);

            Console.WriteLine("shuffle #1:");
            collection.Shuffle();
            Console.WriteLine(collection);
            Console.WriteLine("shuffle #2:");
            collection.Shuffle();
            Console.WriteLine(collection);
            Console.WriteLine("shuffle #3:");
            collection.Shuffle();
            Console.WriteLine(collection);

            Console.WriteLine("sort:");
            collection.Sort(new Quicksorter<int>());
            Console.WriteLine(collection);

            Console.WriteLine("shuffle #4:");
            collection.Shuffle();
            Console.WriteLine(collection);
        }
开发者ID:pkanev,项目名称:Data.Structures,代码行数:43,代码来源:SortableCollectionPlayground.cs

示例11: SortRandomCollectionTest

        public void SortRandomCollectionTest()
        {
            SortableCollection<int> collection =
                new SortableCollection<int>(GenerateSorted(100));

            collection.Shuffle();
            collection.Sort(sorter);

            Assert.IsTrue(IsSorted(collection.Items));
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:10,代码来源:QuickSortTests.cs

示例12: Main

        internal static void Main(string[] args)
        {
            var collection = new SortableCollection<int>(new[] { 77, 332, 651, 98, 1, 5454, 34, 1, 656, 1, 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("SelectionSorter result:");
            collection.Sort(new SelectionSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 77, 332, 651, 98, 1, 5454, 34, 1, 656, 1, 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("Quicksorter result:");
            collection.Sort(new Quicksorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            collection = new SortableCollection<int>(new[] { 77, 332, 651, 98, 1, 5454, 34, 1, 656, 1, 22, 11, 101, 33, 0, 101 });
            Console.WriteLine("MergeSorter result:");
            collection.Sort(new MergeSorter<int>());
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Linear search 11:");
            Console.WriteLine(collection.LinearSearch(11));
            Console.WriteLine();

            Console.WriteLine("Binary search 11:");
            Console.WriteLine(collection.BinarySearch(11));
            Console.WriteLine();

            Console.WriteLine("Shuffle:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();

            Console.WriteLine("Shuffle again:");
            collection.Shuffle();
            collection.PrintAllItemsOnConsole();
        }
开发者ID:bstaykov,项目名称:Telerik-DSA,代码行数:41,代码来源:Program.cs

示例13: Shuffle

        public void Shuffle()
        {
            var collection = new SortableCollection<int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            collection.Shuffle();
            bool shuffled = false;

            for (int i = 0; i < collection.Items.Count - 1; i++)
            {
                if (collection.Items[i] > collection.Items[i + 1])
                {
                    shuffled = true;
                    break;
                }
            }

            Assert.IsTrue(shuffled);
        }
开发者ID:antonpopov,项目名称:Data-Structures-and-Algorithms,代码行数:18,代码来源:ShuffleTests.cs

示例14: Main

    static void Main()
    {
        SortableCollection<int> collection = new SortableCollection<int>(new[] { 34, 12, 11, 312, 86, 14, 5, 88 });

        Console.WriteLine("Collection before sorting:");
        collection.PrintAllItemsOnConsole();
        Console.WriteLine();

        Console.WriteLine("SelectionSorter output:");
        collection.Sort(new SelectionSorter<int>());
        collection.PrintAllItemsOnConsole();
        Console.WriteLine();

        Console.WriteLine("Quicksorter output:");
        collection.Sort(new Quicksorter<int>());
        collection.PrintAllItemsOnConsole();
        Console.WriteLine();

        Console.WriteLine("MergeSorter output:");
        collection.Sort(new MergeSorter<int>());
        collection.PrintAllItemsOnConsole();
        Console.WriteLine();

        Console.WriteLine("Linear search at 86:");
        Console.WriteLine(collection.LinearSearch(86));
        Console.WriteLine();

        Console.WriteLine("Binary search at 14:");
        Console.WriteLine(collection.BinarySearch(14));
        Console.WriteLine();

        Console.WriteLine("Shuffle:");
        collection.Shuffle();
        collection.PrintAllItemsOnConsole();
        Console.WriteLine();
    }
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:36,代码来源:Program.cs

示例15: Main

        static void Main()
        {
            var unsortedCollectionOne = new SortableCollection<int>(new[] { 3, 5, 8, 11, 2, 9, 111, 21, 333, 44 });
            Console.Write("unsortedCollectionOne: ");
            for (int i = 0; i < unsortedCollectionOne.Items.Count; i++)
            {
                Console.Write(unsortedCollectionOne.Items[i]+" ");
            }
            Console.WriteLine();

            Console.Write("unsortedCollectionOne after use of SelectionSorter: ");
            unsortedCollectionOne.Sort(new SelectionSorter<int>());
            for (int i = 0; i < unsortedCollectionOne.Items.Count; i++)
            {
                Console.Write(unsortedCollectionOne.Items[i] + " ");
            }
            Console.WriteLine();

            Console.WriteLine();
            var unsortedCollectionTwo = new SortableCollection<int>(new[] { 7, 5, 8, 11, 2, 9, 1, 21, 3, 44 });
            Console.Write("unsortedCollectionTwo: ");
            for (int i = 0; i < unsortedCollectionOne.Items.Count; i++)
            {
                Console.Write(unsortedCollectionOne.Items[i] + " ");
            }
            Console.WriteLine();

            Console.Write("unsortedCollectionTwo after use of QuickSorter: ");
            unsortedCollectionTwo.Sort(new Quicksorter<int>());
            for (int i = 0; i < unsortedCollectionTwo.Items.Count; i++)
            {
                Console.Write(unsortedCollectionTwo.Items[i] + " ");
            }
            Console.WriteLine();

            Console.WriteLine();
            var unsortedCollectionThree = new SortableCollection<int>(new[] { 10, 5, 56, 11, 2, 9, 9, 21, 3, 99 });
            Console.Write("unsortedCollectionThree: ");
            for (int i = 0; i < unsortedCollectionThree.Items.Count; i++)
            {
                Console.Write(unsortedCollectionThree.Items[i] + " ");
            }
            Console.WriteLine();

            Console.Write("unsortedCollectionThree after use of MergeSorter: ");
            unsortedCollectionThree.Sort(new Quicksorter<int>());
            for (int i = 0; i < unsortedCollectionThree.Items.Count; i++)
            {
                Console.Write(unsortedCollectionThree.Items[i] + " ");
            }
            Console.WriteLine();

            Console.WriteLine();
            Console.Write("Linear search in unsortedCollectionThree 'after sorting' of 21->");
            Console.Write(unsortedCollectionThree.LinearSearch(21));
            Console.WriteLine();
            Console.Write("Linear search in unsortedCollectionThree 'after sorting' of 12345678->");
            Console.Write(unsortedCollectionThree.LinearSearch(12345678));
            Console.WriteLine();

            Console.WriteLine();
            Console.Write("Binary search in unsortedCollectionThree 'after sorting' of 21->");
            Console.Write(unsortedCollectionThree.BinarySearch(21));
            Console.WriteLine();
            Console.Write("Binary search in unsortedCollectionThree 'after sorting' of 12345678->");
            Console.Write(unsortedCollectionThree.BinarySearch(12345678));
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Shuffle:");
            unsortedCollectionThree.Shuffle();
            for (int i = 0; i < unsortedCollectionThree.Items.Count; i++)
            {
                Console.Write(unsortedCollectionThree.Items[i] + " ");
            }
            Console.WriteLine();
            Console.WriteLine();
        }
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:78,代码来源:SortingAndSearchingMain.cs


注:本文中的SortableCollection.Shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。