Пример #1
0
        static void Main(string[] args)
        {
            LC253_MeetingRooms mr = new LC253_MeetingRooms();

            Console.WriteLine(mr.MinMeetingRoomsPriorityQueue(new int[][]
            {
                new int[] { 7, 10 },
                new int[] { 2, 4 }
            }));
            ProducerConsumerWithBlockingQueue pc = new ProducerConsumerWithBlockingQueue();

            pc.Run();

            Cache <int, int> cache = new CacheFactory <int, int>().DefaultCache(3);

            cache.Put(1, 1);
            cache.Put(2, 2);
            cache.Get(1);
            cache.Put(3, 3);
            cache.Get(3);
            cache.Put(4, 4);
            cache.Get(2);
            FindLadders("a", "c", new List <string>()
            {
                "a", "b", "c"
            });
            Console.WriteLine(new _05_Cycle_Detection_Directed_Graph().IsCycleDfs(4, new Dictionary <int, List <int> >()
            {
                { 0, new List <int> {
                      1, 2
                  } },
                { 1, new List <int> {
                      2
                  } },
                { 2, new List <int> {
                      0, 3
                  } },
                { 3, new List <int> {
                      3
                  } },
            }));
            ProducerConsumer q = new ProducerConsumer(2);

            Console.WriteLine("Enqueuing 10 items...");

            for (int i = 0; i < 10; i++)
            {
                int itemNumber = i;      // To avoid the captured variable trap
                q.EnqueueItem(() =>
                {
                    Thread.Sleep(1000);          // Simulate time-consuming work
                    Console.Write(" Task" + itemNumber);
                });
            }

            q.Shutdown(true);
            Console.WriteLine();
            Console.WriteLine("Workers complete!");
            int[][] board =
            {
                new int[] { -1, -1, -1, -1, -1, -1 },
                new int[] { -1, -1, -1, -1, -1, -1 },
                new int[] { -1, -1, -1, -1, -1, -1 },
                new int[] { -1, 35, -1, -1, 13, -1 },
                new int[] { -1, -1, -1, -1, -1, -1 },
                new int[] { -1, 15, -1, -1, -1, -1 }
            };
            int[][] reversed = board.Reverse().ToArray();
            foreach (int[] b in reversed)
            {
                Console.WriteLine(string.Join(",", b));
            }

            EvenOddThreadSync evenOddThreadSync = new EvenOddThreadSync();

            evenOddThreadSync.Run(10);
            _15_Kruskal_MST sp  = new _15_Kruskal_MST();
            var             mst = sp.KruskalMST(
                new Dictionary <int, List <(int, int)> >()
            {
                { 0, new List <(int, int)> {
                      (1, 2), (3, 6)
                  } },
                { 1, new List <(int, int)> {
                      (0, 2), (2, 3), (3, 8), (4, 5)
                  } },