コード例 #1
0
        public void Cal(int pNum, int which)
        {
            cycleLink.Clear();
            //构建循环链表 表示圆圈
            for (int i = 1; i <= pNum; i++)
            {
                cycleLink.Add(i);
            }

            int index   = 0;
            int counter = 0;
            int who     = 0;

            while (cycleLink.GetCycleLinkLength() >= which)
            {
                index = index % cycleLink.GetCycleLinkLength();
                counter++;
                index++;
                if (counter % which == 0)
                {
                    cycleLink.Delete(index, ref who);
                    Console.Write(who + " ");
                    index--;
                }
            }
            Console.WriteLine();
            Console.Write("活着的有:");
            for (int i = 1; i < which; i++)
            {
                cycleLink.GetElement(i, ref who);
                Console.Write(who + " ");
            }
            Console.WriteLine();
            Console.WriteLine();
        }
コード例 #2
0
        public void Cal()
        {
            cycle.Clear();

            for (int i = 0; i < 13; i++)
            {
                //初始化为-1  用来区分头结点
                cycle.Add(-1);
            }

            //第一张肯定是1
            CycleLink <int> .Node node = cycle.GetNodeByIndex(1);
            node.data = 1;
            int index = 0;

            for (int i = 2; i <= 13; i++)
            {
                //设置其他位置的牌  头结点也计算进去了
                while (index < i)
                {
                    node = node.next;
                    if (node.data > 0)
                    {
                        continue;
                    }

                    index++;
                    if (node.data == 0)
                    {
                        index--;                //跳过头结点不能算
                    }
                }

                index     = 0;
                node.data = i;
            }
        }