示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Structural example:");
            AbstractFactory factory1 = new ConcreteFactory1();
            Client          client1  = new Client(factory1);

            client1.Run();

            AbstractFactory factory2 = new ConcreteFactory2();
            Client          client2  = new Client(factory2);

            client2.Run();

            Console.WriteLine();

            Console.WriteLine("Real-world example:");
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();

            Console.ReadKey();
        }
示例#2
0
        static void AbstractFactoryTester()
        {
            #region sample 1
            // Abstract factory #1
            AbstractFactory factory1 = new ConcreteFactory1();
            var             client1  = new Client(factory1);
            client1.Run();

            // Abstract factory #2
            AbstractFactory factory2 = new ConcreteFactory2();
            var             client2  = new Client(factory2);
            client2.Run();
            #endregion


            #region sample 2
            ContinentFactory africa = new AfricaFactory();
            var world = new AnimalWorld(africa);
            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();
            #endregion
        }
示例#3
0
        private static void ShowAbstractFactory()
        {
            Console.WriteLine("================================================");
            Console.WriteLine("Pattern code (AbstractFactory):");
            AbstractFactory factory1 = new ConcreteFactory1();
            Client          client1  = new Client(factory1);

            client1.Run();

            AbstractFactory factory2 = new ConcreteFactory2();
            Client          client2  = new Client(factory2);

            client2.Run();

            Console.WriteLine("Real code (AbstractFactory):");
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
示例#4
0
        static void Main(string[] args)
        {
            #region Example01
            Console.WriteLine("********* Example01 **********");
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);
            world.RunFoodChain();


            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();

            #endregion

            Console.WriteLine("");

            #region Example02
            Console.WriteLine("********* Example02 **********");
            IMobilePhone nokiaMobilePhone = new Nokia();
            MobileClient nokiaClient      = new MobileClient(nokiaMobilePhone);

            Console.WriteLine("********* NOKIA **********");
            Console.WriteLine(nokiaClient.GetSmartPhoneModelDetails());
            Console.WriteLine(nokiaClient.GetNormalPhoneModelDetails());

            IMobilePhone samsungMobilePhone = new Samsung();
            MobileClient samsungClient      = new MobileClient(samsungMobilePhone);

            Console.WriteLine("******* SAMSUNG **********");
            Console.WriteLine(samsungClient.GetSmartPhoneModelDetails());
            Console.WriteLine(samsungClient.GetNormalPhoneModelDetails());

            #endregion

            Console.WriteLine("");

            #region Example03
            Console.WriteLine("********* Example03 **********");
            Document[] documents = new Document[2];

            documents[0] = new Resume();
            documents[1] = new Report();

            // Display document pages

            foreach (Document document in documents)
            {
                Console.WriteLine("\n" + document.GetType().Name + "--");
                foreach (Page page in document.Pages)
                {
                    Console.WriteLine(" " + page.GetType().Name);
                }
            }
            #endregion

            Console.ReadKey();
        }
        public void testInit_manuallyRegistratin()
        {
            // create instance of the container
            WindsorContainer container = new WindsorContainer(new XmlInterpreter());

            // Resolve with Resolve methods
            africaFactory  = container.Resolve <AfricaFactory>();
            americaFactory = container.Resolve <AmericaFactory>();
        }
示例#6
0
文件: Tests.cs 项目: TomPallister/PoC
        public void FirstTest()
        {
            ContinentFactory africa = new AfricaFactory();
            var world = new AnimalWorld(africa);
            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
示例#7
0
        public static void Main()
        {
            //AfricaFactory is Concrete Factory.
            //ContinentFactory is Abstract Factory.
            ContinentFactory africa  = new AfricaFactory();
            ContinentFactory america = new AmericaFactory();

            //同じ要領で操作が実行できる
            africa.CreateCarnivore();
            america.CreateHerbivore();
        }
示例#8
0
        static void Main(string[] args)
        {
            ContinentFactory myContinentFactory = new AfricaFactory();
            AnimalWorld      myAnimalWorld      = new AnimalWorld(myContinentFactory);

            myAnimalWorld.RunFoodChain();

            myContinentFactory = new AmericaFactory();
            myAnimalWorld      = new AnimalWorld(myContinentFactory);
            myAnimalWorld.RunFoodChain();
        }
        public static void Execucao()
        {
            ContinenteFactory africa = new AfricaFactory();
            var animais = new Animais(africa);

            animais.CacarComida();

            ContinenteFactory america = new AmericaFactory();

            animais = new Animais(america);
            animais.CacarComida();
        }
示例#10
0
        public static void Test()
        {
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
        public void Execute()
        {
            ContinentFactory afrika = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(afrika);

            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
示例#12
0
        public static void Run()
        {
            ContinentFactory africa = new AfricaFactory();
            var animals             = new Animals(africa);

            animals.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            animals = new Animals(america);
            animals.RunFoodChain();
        }
示例#13
0
        public void AbstractFactoryTest()
        {
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            Assert.IsTrue(world.RunFoodChain() == "Lion eats Wildebeast");

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            Assert.IsTrue(world.RunFoodChain() == "Wolf eats Bison");
        }
示例#14
0
        public static void TestContinentFactory()
        {
            ContinentFactory africa = new AfricaFactory();
            var world = new AnimalWorld(africa);

            StringAssert.AreEqualIgnoringCase("Lion eats Wildebeest", world.RunFoodChain(true));

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            StringAssert.AreEqualIgnoringCase("Wolf eats Bison", world.RunFoodChain(true));
        }
示例#15
0
        private static void AbstractFactoryDemo()
        {
            var africa = new AfricaFactory();
            var world  = new AnimalWorld(africa);

            world.RunFoodChain();

            var america = new AmericaFactory();

            world = new AnimalWorld(america);

            world.RunFoodChain();
        }
示例#16
0
        public void testInit_manuallyRegistratin()
        {
            // create instance of the container
            WindsorContainer container = new WindsorContainer();

            // Register Components
            container.Register(Component.For <AfricaFactory>().ImplementedBy <AfricaFactory>());
            container.Register(Component.For <AmericaFactory>().ImplementedBy <AmericaFactory>());

            // Resolve with Resolve methods
            africaFactory  = container.Resolve <AfricaFactory>();
            americaFactory = container.Resolve <AmericaFactory>();
        }
示例#17
0
        public static void Execute()
        {
            // Cria e executa o mundo animal Africano
            var africa = new AfricaFactory();
            var mundo  = new MundoAnimal(africa);

            mundo.AdministrarCadeiaAlimentar();

            // Cria e executa o mundo animal Americano
            var america = new AmericaFactory();

            mundo = new MundoAnimal(america);
            mundo.AdministrarCadeiaAlimentar();
        }
示例#18
0
        static void RunAbstractFactoryRealWorld()
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Run()
        {
            // Create and run the African animal world
            var africa = new AfricaFactory();
            var world  = new AnimalWorld(africa);

            world.RunFoodChain();

            // Create and run the American animal world
            var america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
示例#20
0
        static void Main(string[] args)
        {
            ContinentFactory firstFactory = new AfricaFactory();
            Carnivore        firstAnimal  = firstFactory.CreateCarnivore();

            Console.WriteLine($"You could see {firstAnimal.GetType().Name} In Africa.");

            ContinentFactory secondFactory = new AmericaFactory();
            Carnivore        secondAnimal  = secondFactory.CreateCarnivore();

            Console.WriteLine($"You could see {secondAnimal.GetType().Name} In America.");

            Console.ReadLine();
        }
示例#21
0
        public void TestCreateAndRunAnimal()
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
示例#22
0
        public static IContinetFactory CreateContinent(string continet)
        {
            IContinetFactory cf;

            if (continet.ToLower().Trim() == "america")
            {
                cf = new AmericaFactory();
            }
            else
            {
                cf = new AfricaFactory();
            }

            return(cf);
        }
示例#23
0
        static void Main(string[] args)
        {
            ContinentFactory africa      = new AfricaFactory();
            AnimalWorld      animalWorld = new AnimalWorld(africa);

            animalWorld.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            animalWorld = new AnimalWorld(america);
            animalWorld.RunFoodChain();


            Console.ReadKey();
        }
示例#24
0
        public static void Main(string[] args)
        {
            //Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld world = new AnimalWorld(africa);
            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory amercia = new AmericaFactory();
            world = new AnimalWorld(amercia);
            world.RunFoodChain();

            //wait for user input before closing application
            Console.ReadKey(true);
        }
示例#25
0
        private static void TestFactory()
        {
            Console.WriteLine("Testing factory...");
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            var world = new AnimalWorld(africa);

            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
        public void MainTest()
        {
            // TODO
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();

            Assert.AreEqual(1, 1);
        }
示例#27
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public static void Main()
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);

            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();

            // Wait for user input
            Console.ReadKey();
        }
示例#28
0
        static void Main(string[] args)
        {
            // Create and run the African animal world

            ContinentFactory australia = new AustraliaFactory();
            AnimalWorld      world     = new AnimalWorld(australia);

            world.RunFoodChain();

            // Create and run the American animal world

            ContinentFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();

            // Wait for user input

            Console.ReadKey();
        }
        //Real-world
        public static void AbstractFactoryRealWorld()
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();

            Log.WriteLine("{0} has Created", africa.GetType().Name);
            var world = new AnimalWorld(africa);

            Log.WriteLine("{0} has Created", world.GetType().Name);
            Log.WriteLine("Animal World Create Herbivore and Carnivore");
            Log.WriteLine("Animal World Run Food Chain");
            world.RunFoodChain();

            Log.AddSeparator(5);
            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();

            Log.WriteLine("{0} has Created", america.GetType().Name);
            world = new AnimalWorld(america);
            Log.WriteLine("{0} has Created", world.GetType().Name);
            Log.WriteLine("Animal World Create Herbivore and Carnivore");
            Log.WriteLine("Animal World Run Food Chain");
            world.RunFoodChain();
        }
        public void AbstractFactory_Works()
        {
            // arrange
            var outputWriter = new OutputWriter();
            AutoFacInstance.Container = base.GetAutoFacContainer(outputWriter);
            
            // Create and run the African animal world
            var africa = new AfricaFactory();
            var africanWorld = new AnimalWorld(africa);
            
            // Create and run the American animal world
            var america = new AmericaFactory();
            var americanWorld = new AnimalWorld(america);

            // act
            africanWorld.RunFoodChain();
            americanWorld.RunFoodChain();

            // assert
            Assert.AreEqual(outputWriter.Outputs.Count, 2);
            Assert.IsNotNull(outputWriter.Outputs);
            Assert.IsNotNull(outputWriter.Outputs.Find(x => x == "Lion eats Wildebeest"));
            Assert.IsNotNull(outputWriter.Outputs.Find(x => x == "Wolf eats Bison"));
        }
 public void testClean()
 {
     africaFactory  = null;
     americaFactory = null;
 }
示例#32
0
        static void Main(string[] args)
        {
            #region Design Patterns
            #region Decorator Pattern Example
            Espresso beverage1 = new Espresso();
            Console.WriteLine("Double Mocha Esspresso");
            Mocha d1 = new Mocha(beverage1);
            Mocha d2 = new Mocha(d1);
            Console.WriteLine(d2.Cost() + " " + d2.Description);

            Console.WriteLine("\n House Blend, Moch, Whip");
            HouseBlend beverage2 = new HouseBlend();
            Mocha      d3        = new Mocha(beverage2);
            Whip       d4        = new Whip(d3);
            Console.WriteLine(d4.Cost() + " " + d4.Description);
            #endregion

            #region Factory Pattern
            // Note: constructors call Factory Method
            Document[] documents = new Document[2];

            documents[0] = new Resume();
            documents[1] = new Report();

            // Display document pages
            foreach (Document document in documents)
            {
                Console.WriteLine("\n" + document.GetType().Name + "--");
                foreach (Page page in document.Pages)
                {
                    Console.WriteLine(" " + page.GetType().Name);
                }
            }
            #endregion

            #region Abstract Factory Pattern
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld      world  = new AnimalWorld(africa);
            world.RunFoodChain();

            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();
            #endregion

            #region Singleton
            Console.WriteLine(Singleton.Math.Instance.add(34, 3));
            #endregion

            #region Obsever Pattern
            BaggageHandler  provider  = new BaggageHandler();
            ArrivalsMonitor observer1 = new ArrivalsMonitor("BaggageClaimMonitor1");
            ArrivalsMonitor observer2 = new ArrivalsMonitor("SecurityExit");

            provider.BaggageStatus(712, "Detroit", 3);
            observer1.Subscribe(provider);
            provider.BaggageStatus(712, "Kalamazoo", 3);
            provider.BaggageStatus(400, "New York-Kennedy", 1);
            provider.BaggageStatus(712, "Detroit", 3);
            observer2.Subscribe(provider);
            provider.BaggageStatus(511, "San Francisco", 2);
            provider.BaggageStatus(712);
            observer2.Unsubscribe();
            provider.BaggageStatus(400);
            provider.LastBaggageClaimed();
            #endregion

            #region Strategy Pattern
            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();
            #endregion

            #region Composite Pattern
            CompositeElement root = new CompositeElement("Picture");
            root.Add(new PrimitiveElement("Red Line"));
            root.Add(new PrimitiveElement("Blue Circle"));
            root.Add(new PrimitiveElement("Green Box"));

            CompositeElement comp = new CompositeElement("Two Circles");
            comp.Add(new PrimitiveElement("Black Circle"));
            comp.Add(new PrimitiveElement("White Circle"));
            root.Add(comp);

            PrimitiveElement pe = new PrimitiveElement("Yellow Line");
            root.Add(pe);
            root.Remove(pe);

            root.Display(1);
            #endregion

            #region Command Pattern
            User user = new User();

            user.Compute('+', 100);
            user.Compute('-', 50);
            user.Compute('*', 10);
            user.Compute('/', 2);

            user.Undo(4);
            user.Redo(3);
            #endregion

            #region COR (Chain of Responsibility)
            // Setup Chain of Responsibility
            Handler h1 = new ConcreteHandlerA();
            Handler h2 = new ConcreteHandlerB();
            Handler h3 = new ConcreteHandlerC();
            h2.SetSuccessor(h3);
            h1.SetSuccessor(h2);


            // Generate and process request
            int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 };

            foreach (int request in requests)
            {
                h1.HandleRequest(request);
            }
            #endregion

            #endregion

            #region AD

            #region List
            MyArrayList list = new MyArrayList(5);
            //setting values
            list.add(1);
            list.add(2);
            list.add(3);
            list.add(4);
            list.add(5);

            Console.WriteLine(list.get(2) + " staat op positie 2");
            //testing print function
            list.print();
            //testing set function
            list.set(2, 10); //true
            list.print();
            list.set(10, 2); //false
            //occurences test
            list.set(0, 2);
            list.set(4, 2);
            list.countOccurences(2);
            //testing clear
            list.clear();
            list.print();

            MyLinkedList <int> linkedList = new MyLinkedList <int>();
            linkedList.addFirst(1);
            linkedList.addFirst(12);
            linkedList.addFirst(3);
            linkedList.addFirst(4);
            linkedList.addFirst(5);
            linkedList.insert(0, 123);
            linkedList.remove(12);
            MyLinkedList <int> .printList(linkedList);

            Console.ReadLine();
            #endregion

            #region Graph
            Graph g = new Graph();

            try
            {
                StreamReader d = new StreamReader(Console.ReadLine());
                string       line;
                while ((line = d.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                    string[] words = line.Split(' ');
                    try
                    {
                        if (words.Length > 3)
                        {
                            Console.WriteLine("Skipping bad line: " + line);
                            continue;
                        }
                        string source = words[0];
                        string dest   = words[1];
                        int    cost   = Int32.Parse(words[2]);

                        g.addEdge(source, dest, cost);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Skipping bad line: " + line);
                        Console.WriteLine(e);
                    }
                }
            }
            catch (Exception e) { Console.WriteLine(e); }


            //while (processRequest(g));
            #endregion

            #region Binairy tree
            string seperator = "-----------------------------------------------------------------------";
            Console.WriteLine(seperator);
            Console.WriteLine("Binary Tree Basic: ");
            BinaryNode <int> NodeA = new BinaryNode <int>(2);
            BinaryNode <int> NodeB = new BinaryNode <int>(5);
            BinaryNode <int> NodeC = new BinaryNode <int>(6);
            BinaryNode <int> NodeD = new BinaryNode <int>(3);
            BinaryNode <int> NodeE = new BinaryNode <int>(7);
            BinaryNode <int> NodeF = new BinaryNode <int>(10);
            BinaryNode <int> NodeG = new BinaryNode <int>(1);

            NodeE.setRight(NodeG);

            NodeA.setLeft(NodeC);
            NodeA.setRight(NodeD);

            NodeB.setLeft(NodeE);
            NodeB.setRight(NodeF);


            BinaryTree <int> tree = new BinaryTree <int>(12);
            tree.Root.setLeft(NodeA);
            tree.Root.setRight(NodeB);

            tree.printPreOrder();
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Binary Search Tree: ");
            BinaryTree <int> BST = new BinaryTree <int>();
            BST.Insert(5);
            BST.Insert(1254);
            BST.Insert(252);
            BST.Insert(378);
            BST.Insert(45);

            BST.Insert(668);
            BST.Insert(71);
            BST.Insert(8);
            BST.Insert(942);
            //fail test
            BST.Insert(1);

            Console.WriteLine(seperator);
            Console.WriteLine("Printing in order: ");
            BST.printInOrder();
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Finding Min:");
            Console.WriteLine(BST.FindMin());
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Finding Max: ");
            Console.WriteLine(BST.FindMax());
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Finding value 5:");
            Console.WriteLine(BST.Find(5));
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Removing 5");
            BST.Remove(5);
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Printing in order: ");
            BST.printInOrder();
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Removing Min");
            BST.RemoveMin();
            Console.ReadLine();

            Console.WriteLine(seperator);
            Console.WriteLine("Printing in order: ");
            BST.printInOrder();
            Console.ReadLine();
            #endregion

            #region Max heap
            MaxHeap theHeap = new MaxHeap(21);
            theHeap.Insert(40);
            theHeap.Insert(70);
            theHeap.Insert(20);
            theHeap.Insert(60);
            theHeap.Insert(50);
            theHeap.Insert(100);
            theHeap.Insert(82);
            theHeap.Insert(35);
            theHeap.Insert(90);
            theHeap.Insert(10);
            theHeap.DisplayHeap();

            Console.WriteLine("Inserting a new node with value 120");
            theHeap.Insert(120);
            theHeap.DisplayHeap();

            Console.WriteLine("Removing max element");
            theHeap.Remove();
            theHeap.DisplayHeap();

            Console.WriteLine("Changing root to 130");
            theHeap.HeapIncreaseDecreaseKey(0, 130);
            theHeap.DisplayHeap();

            Console.WriteLine("Changing root to 5");
            theHeap.HeapIncreaseDecreaseKey(0, 5);
            theHeap.DisplayHeap();
            Console.ReadLine();
            #endregion

            #region Min heap
            int[] arrA = { 50, 2, 30, 7, 40, 4, 10, 16, 12 };
            Console.WriteLine("Original Array : ");
            for (int i = 0; i < arrA.Length; i++)
            {
                Console.Write("  " + arrA[i]);
            }
            MinHeap m = new MinHeap(arrA.Length);
            Console.WriteLine("\nMin-Heap : ");
            m.createHeap(arrA);
            m.display();
            Console.WriteLine("Extract Min :");
            for (int i = 0; i < arrA.Length; i++)
            {
                Console.Write("  " + m.extractMin());
            }
            #endregion

            #region Sorting
            Console.WriteLine();
            int[] tmpArray = { 0, 15, 48, 60, 88, 123, 1, 5, 4, 12, 99, 11, 200, 41 };
            Console.WriteLine(seperator);
            Console.WriteLine("Base Array: ");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);
            var watch = System.Diagnostics.Stopwatch.StartNew();
            SortingAlgorithms.ShellSort(tmpArray);
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine("Shell sorted Array in: " + elapsedMs + "ms");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);
            Console.ReadKey();

            tmpArray = new[] { 0, 15, 48, 60, 88, 123, 1, 5, 4, 12, 99, 11, 200, 41 };
            Console.WriteLine("Base Array: ");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);

            watch = System.Diagnostics.Stopwatch.StartNew();
            SortingAlgorithms.PerformInsertionSort(tmpArray);
            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine("Insertion sorted Array in: " + elapsedMs + "ms");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);
            Console.ReadKey();

            tmpArray = new[] { 0, 15, 48, 60, 88, 123, 1, 5, 4, 12, 99, 11, 200, 41 };
            Console.WriteLine("Base Array: ");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);

            watch = System.Diagnostics.Stopwatch.StartNew();
            SortingAlgorithms.MergeSort(tmpArray);
            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine("Merge sorted Array in: " + elapsedMs + "ms");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);
            Console.ReadKey();

            tmpArray = new[] { 0, 15, 48, 60, 88, 123, 1, 5, 4, 12, 99, 11, 200, 41, 46 };
            Console.WriteLine("Base Array: ");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);

            watch = System.Diagnostics.Stopwatch.StartNew();
            SortingAlgorithms.QuickSort(tmpArray, 0, tmpArray.Length - 1);
            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine("Quick sorted Array in: " + elapsedMs + "ms");
            SortingAlgorithms.Show_array_elements(tmpArray);
            Console.WriteLine(seperator);
            Console.ReadKey();
            #endregion
            #endregion
            Console.ReadKey();
        }
示例#33
0
  public static void Main( string[] args )
  {
    // Create and run the Africa animal world
    ContinentFactory africa = new AfricaFactory();
    AnimalWorld world = new AnimalWorld( africa );
    world.RunFoodChain();

    // Create and run the America animal world
    ContinentFactory america = new AmericaFactory();
    world = new AnimalWorld( america );
    world.RunFoodChain();

    Console.Read();
  }