コード例 #1
0
ファイル: QueueTasks.cs プロジェクト: Nero0909/AlgorithmsNet
        public static string JosephTask(int N, int M)
        {
            var result  = new StringBuilder(N);
            var victims = new ListQueue <int>();

            for (var i = 0; i < N; i++)
            {
                victims.Enqueue(i);
            }

            var currPosition = 1;

            while (victims.Size > 1)
            {
                if (currPosition % M == 0)
                {
                    var luckyMan = victims.Dequeue();
                    result.Append(luckyMan);
                    result.Append(" ");
                }
                else
                {
                    var unluckyMan = victims.Dequeue();
                    victims.Enqueue(unluckyMan);
                }

                currPosition++;
            }

            var looser = victims.Dequeue();

            result.Append(looser);

            return(result.ToString());
        }
コード例 #2
0
 public void AddUnit(HexUnit newUnit)
 {
     if (newUnit == null)
     {
         throw new NullReferenceException("newUnit is null!");
     }
     newUnit.OwnerId = Id;
     newUnit.GetComponent <Recycle>().onRecyclingCallback += RemoveUnit;
     _units.Enqueue(newUnit);
     Messenger.Broadcast(ON_UNIT_ADDED, newUnit);
 }
コード例 #3
0
 /// <summary>
 /// Enqueues the player.
 /// </summary>
 /// <param name="player">The player.</param>
 public static void EnqueuePlayer(PlayerInfoModel player)
 {
     lock (player)
     {
         PlayersQueue.Enqueue(player);
     }
 }
コード例 #4
0
 /// <summary>
 /// ActionScheduleを初期化する
 /// </summary>
 /// <param name="schedule">PlayerIDの並びで行動の順番を格納するキュー</param>
 /// <param name="players">Player情報の配列、この配列の順番が行動の順番となる</param>
 private static void ResetActionSchedule(ListQueue <int> schedule, IReadOnlyList <Player> players)
 {
     schedule.Clear();
     for (var i = 0; i < players.Count * 3; i++)
     {
         schedule.Enqueue(players[i % players.Count].PlayerID);
     }
 }
コード例 #5
0
ファイル: Tests.cs プロジェクト: medegor44/Students
        public void CheckContainsQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 6; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var resultArray = queueArray.Contains(1);
            var resultList  = queueList.Contains(1);

            Assert.True(resultArray);
            Assert.True(resultList);
        }
コード例 #6
0
ファイル: Tests.cs プロジェクト: medegor44/Students
        public void CheckClearQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            queueArray.Clear();
            queueList.Clear();

            Assert.Equal(0, queueArray.Count());
            Assert.Equal(0, queueList.Count());
        }
コード例 #7
0
ファイル: Tests.cs プロジェクト: medegor44/Students
        public void CheckDequeueQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            queueArray.Dequeue();
            queueList.Dequeue();

            Assert.Equal(2, queueArray.Peek());
            Assert.Equal(2, queueList.Peek());
        }
コード例 #8
0
ファイル: Tests.cs プロジェクト: medegor44/Students
        public void CheckPeekQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var resultArray = queueArray.Peek();
            var resultList  = queueList.Peek();

            Assert.Equal(1, resultArray);
            Assert.Equal(1, resultList);
        }
コード例 #9
0
ファイル: Tests.cs プロジェクト: medegor44/Students
        public void CheckCountQueue()
        {
            MyQueue <int> queueArray = new ArrayQueue <int>();
            MyQueue <int> queueList  = new ListQueue <int>();

            for (int i = 1; i < 11; i++)
            {
                queueArray.Enqueue(i);
                queueList.Enqueue(i);
            }

            var countArray = queueArray.Count();
            var countList  = queueList.Count();

            Assert.Equal(10, countArray);
            Assert.Equal(10, countList);
        }
コード例 #10
0
        /// <summary>
        /// Boton para agregar un elemento a la cola
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Enqueue_Click(object sender, RoutedEventArgs e)
        {
            string input = tB_Enqueue.Text;

            if (string.IsNullOrEmpty(input))
            {
                MessageBox.Show("Revisa los datos.");
                return;
            }
            else
            {
                queue.Enqueue(input);
                // actualizar representacion grafica de cola
                l_RepCola.Content  = string.Concat("Cola: ", queue.ToString());
                l_Cantidad.Content = string.Concat("Cantidad de elementos en la cola: ", queue.Size());
                tB_Enqueue.Text    = string.Empty;
            }
        }
コード例 #11
0
    static void Main(string[] args)
    {
        ListQueue <string> queue = new ListQueue <string>();

        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        for (int i = 1; i <= 10; i++)
        {
            var text = String.Format("Test{0}", i);
            queue.Enqueue(text);
            Console.WriteLine("Just enqueued: {0}", text);
        }
        Console.WriteLine();
        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        var peekText = queue.Peek();

        Console.WriteLine("Just peeked at: {0}", peekText);
        Console.WriteLine();
        var textToRemove = "Test5";

        queue.Remove(textToRemove);
        Console.WriteLine("Just removed: {0}", textToRemove);
        Console.WriteLine();
        var queueCount = queue.Count;

        for (int i = 0; i < queueCount; i++)
        {
            var text = queue.Dequeue();
            Console.WriteLine("Just dequeued: {0}", text);
        }
        Console.WriteLine();
        Console.WriteLine("Item count in ListQueue: {0}", queue.Count);
        Console.WriteLine();
        Console.WriteLine("Now try to ADD an item...should cause an exception.");
        queue.Add("shouldFail");
    }
コード例 #12
0
ファイル: Program.cs プロジェクト: catdog50rus/CodeBlog
        static void Main()
        {
            var listQueue = new ListQueue <int>();

            listQueue.Enqueue(1);
            listQueue.Enqueue(3);
            listQueue.Enqueue(4);
            listQueue.Enqueue(6);
            listQueue.Enqueue(9);
            DisplayQueue(listQueue);
            Console.WriteLine("Добавим в очередь элемент '7'");
            listQueue.Enqueue(7);
            DisplayItem(listQueue);
            listQueue.Clear();
            DisplayQueue(listQueue);

            var arrayQueue = new ArrayQueue <string>(10);

            arrayQueue.Enqueue("1");
            arrayQueue.Enqueue("2");
            arrayQueue.Enqueue("5");
            arrayQueue.Enqueue("6");
            arrayQueue.Enqueue("ten");
            DisplayQueue(arrayQueue);
            Console.WriteLine("Добавим в очередь элемент 'seven'");
            arrayQueue.Enqueue("seven");
            DisplayItem(arrayQueue);
            arrayQueue.Clear();
            DisplayQueue(arrayQueue);

            var linkedListQueue = new LinkedQueue <int>();

            linkedListQueue.Enqueue(1);
            linkedListQueue.Enqueue(3);
            linkedListQueue.Enqueue(4);
            linkedListQueue.Enqueue(6);
            linkedListQueue.Enqueue(9);
            DisplayQueue(linkedListQueue);
            Console.WriteLine("Добавим в очередь элемент '7'");
            linkedListQueue.Enqueue(7);
            DisplayItem(linkedListQueue);
            linkedListQueue.Clear();
            DisplayQueue(linkedListQueue);

            var listDeque = new ListDeque <int>();

            listDeque.AddFirst(1);
            listDeque.AddFirst(3);
            listDeque.AddFirst(4);
            listDeque.AddLast(6);
            listDeque.AddLast(9);
            DisplayItem(listDeque);
            DisplayQueue(listDeque);
            Console.WriteLine();
            listDeque.AddLast(5);
            DisplayItem(listDeque);
            Console.WriteLine(listDeque.RemoveFirst());
            DisplayItem(listDeque);


            var linkedDeque = new LinkedListDeque <int>();

            linkedDeque.AddFirst(1);
            linkedDeque.AddFirst(3);
            linkedDeque.AddFirst(4);
            linkedDeque.AddLast(6);
            linkedDeque.AddLast(9);
            DisplayItem(linkedDeque);
            DisplayQueue(linkedDeque);
            Console.WriteLine();
            linkedDeque.AddLast(5);
            DisplayItem(linkedDeque);
            Console.WriteLine(linkedDeque.RemoveFirst());
            DisplayItem(linkedDeque);
        }
コード例 #13
0
        private void StartOnXml_OnClick(object sender, RoutedEventArgs e)
        {
            if (TabControl0.SelectedIndex == 2 && string.IsNullOrEmpty(waterMarkImg))
            {
                System.Windows.Forms.MessageBox.Show("请选择要添加水印的图片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //获取设置
            cpuCount    = AppConfigHelper.GetAppConfigInt("CpuCount");
            threadCount = AppConfigHelper.GetAppConfigInt("ThreadCount");
            //清空当前列表
            ListQueue.Clear();
            //清空进度条
            this.pb.Maximum = 0;
            this.tb.Text    = "0%";
            this.pb.Value   = 0;

            //先从根目录下查找xml
            XmlDocument xmldoc = new XmlDocument();

            try
            {
                string xmlPath = System.AppDomain.CurrentDomain.BaseDirectory + "watermark.xml";
                xmldoc.Load(xmlPath);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("xml文件加载出错", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LogHelper.AddErrorLog(ex.ToString());
                return;
            }
            //获取节点列表
            XmlNodeList topNode = xmldoc.DocumentElement.ChildNodes;

            foreach (XmlElement element in topNode)
            {
                var str         = element.InnerText;
                var item        = new VideoMp4();
                var oldFilePath = str; // newFilePath.Substring(0,newFilePath.LastIndexOf("."))
                var filename    = oldFilePath.Substring(oldFilePath.LastIndexOf("\\")).Replace("\\", "");
                var fileformat  = filename.Substring(filename.LastIndexOf("."));
                var newfilename = filename.Substring(0, filename.LastIndexOf(".")) + "_znykt_cnki" + fileformat;
                var newFilePath = oldFilePath.Substring(0, oldFilePath.LastIndexOf("\\")) + "\\" + newfilename;
                item.CmdString   = string.Format(" -y -i \"{0}\" -vf \"movie={1},scale=170:60[watermark];[in][watermark]overlay=main_w-overlay_w-10:10[out]\" \"{2}\"", oldFilePath, waterMarkImg, newFilePath);
                item.NewFileName = newfilename;
                item.NewFilePath = newFilePath;
                item.OldFilePath = oldFilePath;
                item.OldfileName = filename;
                ListQueue.Enqueue(item);
            }

            if (ListQueue.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("该路径下未找到MP4格式的视频", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            LogTextBox.Clear();
            LogTextBox.Text = "该目录下共找到 " + ListQueue.Count + " 个视频,开始进行转换......\n";
            iAmount         = ListQueue.Count;
            iCount          = 0;
            iNow            = 0;
            Thread thread = new Thread(ThreadStart);

            thread.IsBackground = true;
            thread.Start();

            Select.IsEnabled = false;
            Start.IsEnabled  = false;

            Select1.IsEnabled = false;
            Start1.IsEnabled  = false;

            pb.Maximum = ListQueue.Count;
        }
コード例 #14
0
        private static int FloodFill(Cell startCell, List <Cell> cellsArea, List <CellStruct> listCells, HasSomething has, bool checkFirst)
        {
            int tileTraversed = 0;

            for (int i = 0; i < listCells.Count; i++)
            {
                listCells[i].visited = false;
            }

            if (checkFirst)
            {
                if (has(startCell.X, startCell.Y, listCells))
                {
                    return(0);
                }
            }


            ListQueue <CellStruct> queue     = new ListQueue <CellStruct>();
            CellStruct             firstCell = listCells.FirstOrDefault(c => c.x == startCell.X && c.y == startCell.Y);

            firstCell.visited = true;
            queue.Enqueue(firstCell);

            while (queue.Count != 0)
            {
                CellStruct node = queue.Dequeue();
                tileTraversed++;

                //west
                if (HasCellUnvisited(node.x - 1, node.y, listCells))
                {
                    if (has(node.x - 1, node.y, listCells))
                    {
                        return(tileTraversed);
                    }

                    CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x - 1 && c.y == node.y);
                    openNode.visited = true;
                    queue.Enqueue(openNode);
                }
                //east
                if (HasCellUnvisited(node.x + 1, node.y, listCells))
                {
                    if (has(node.x + 1, node.y, listCells))
                    {
                        return(tileTraversed);
                    }
                    CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x + 1 && c.y == node.y);
                    openNode.visited = true;
                    queue.Enqueue(openNode);
                }
                //north
                if (HasCellUnvisited(node.x, node.y - 1, listCells))
                {
                    if (has(node.x, node.y - 1, listCells))
                    {
                        return(tileTraversed);
                    }
                    CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y - 1);
                    openNode.visited = true;
                    queue.Enqueue(openNode);
                }
                //south
                if (HasCellUnvisited(node.x, node.y + 1, listCells))
                {
                    if (has(node.x, node.y + 1, listCells))
                    {
                        return(tileTraversed);
                    }
                    CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y + 1);
                    openNode.visited = true;
                    queue.Enqueue(openNode);
                }
            }
            return(tileTraversed);
        }