コード例 #1
0
ファイル: Program.cs プロジェクト: halityurtsever/KnowHow
        static void Main(string[] args)
        {
            SortedList sortedList = new SortedList();

            //bubble sort
            sortedList.List         = new[] { 9, 3, 6, 1, 5, 8, 2, 7 };
            sortedList.SortStrategy = new BubbleSortStrategy();
            sortedList.Sort();

            //selection sort
            sortedList.List         = new[] { 12, 65, 34, 45, 98, 56, 41, 76 };
            sortedList.SortStrategy = new SelectionSortStrategy();
            sortedList.Sort();

            //insertion sort
            sortedList.List         = new[] { 78, 82, 39, 15, 53, 66, 21, 17 };
            sortedList.SortStrategy = new InsertionSortStrategy();
            sortedList.Sort();

            //merge sort
            sortedList.List         = new[] { 926, 515, 856, 142, 917, 721, 873, 319, 480 };
            sortedList.SortStrategy = new MergeSortStrategy();
            sortedList.Sort();

            Console.ReadLine();
        }
コード例 #2
0
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            public static void Main()
            {
                // Two contexts following different strategies

                SortedList studentRecords = new SortedList();

                studentRecords.Add("Samual");
                studentRecords.Add("Jimmy");
                studentRecords.Add("Sandra");
                studentRecords.Add("Vivek");
                studentRecords.Add("Anna");

                studentRecords.SetSortStrategy(new QuickSort());
                studentRecords.Sort();

                studentRecords.SetSortStrategy(new ShellSort());
                studentRecords.Sort();

                studentRecords.SetSortStrategy(new MergeSort());
                studentRecords.Sort();

                // Wait for user

                Console.ReadKey();
            }
コード例 #3
0
        static void Main(string[] args)
        {
            // Two contexts following different strategies

            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user

            Console.ReadKey();



            Console.ReadLine();


            Context context;

            //Three context following different strategies
            context = new Context(new ConcreteStrategyA());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyB());
            context.ContextInterface();

            context = new Context(new ConcreteStrategyC());
            context.ContextInterface();

            //Wait for user
            Console.ReadKey();
        }
コード例 #4
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Execute()
        {
            // Two contexts following different strategies
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();
        }
コード例 #5
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Two contexts following different strategies
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user
            Console.ReadKey();
        }