Esempio n. 1
0
        public void QueueTest_當存入輸入時_IsEmpty為false()
        {
            var expect = new int[] { 24, 12, 16, 22 };

            var queue = new CircleQueue <int>();

            foreach (var i in expect)
            {
                queue.Enqueue(i);
            }

            Assert.IsFalse(queue.IsEmpty);
        }
Esempio n. 2
0
    /// <summary>
    /// 输出一条日志信息
    /// </summary>
    /// <param name="hash"></param>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    public static void LogTrack(ushort hash, string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7)
    {
        //ms_currLogTrackItems.Add(hash);
        //ms_currLogTrackArgs.Add(arg1);
        //ms_currLogTrackArgs.Add(arg2);
        //ms_currLogTrackArgs.Add(arg3);
        //ms_currLogTrackArgs.Add(arg4);
        //ms_currLogTrackArgs.Add(arg5);
        //ms_currLogTrackArgs.Add(arg6);
        //ms_currLogTrackArgs.Add(arg7);
        LogTrackFunc ltf = new LogTrackFunc();

        ltf.ID   = hash;
        ltf.Args = new List <string> {
            arg1, arg2, arg3, arg4, arg5, arg6, arg7
        };
        LogTrackLoopQueue.Enqueue(ltf);
    }
Esempio n. 3
0
        private void CompareMatch <T>(IEnumerable <T> expect)
        {
            var queue = new CircleQueue <T>();

            foreach (var i in expect)
            {
                queue.Enqueue(i);
            }

            var actual = new List <T>();

            while (!queue.IsEmpty)
            {
                var i = queue.Dequeue();
                actual.Add(i);
            }

            expect.ToExpectedObject().ShouldMatch(actual);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine(ReverseWords.MyReverseWords("a good   example"));
            Console.ReadLine();
            #region 雪花算法生成ID
            // SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator();

            #endregion

            SingleLinkedList <int> list = new SingleLinkedList <int>();
            for (int i = 0; i < 4; i++)
            {
                list.InsertToTail(i + 1);
            }
            list.Reverse(list.Head);
            Array_Test();

            Merge_LinkedList_Test();
            var q = new Person {
                Id = 1, Name = "marson"
            };
            var p = q;
            q = new Person {
                Id = 2, Name = "shine"
            };
            Console.WriteLine(ReferenceEquals(p, q));
            Console.WriteLine(q == p);
            Console.WriteLine("q.hashCode=" + q.GetHashCode() + " p.hashCode=" + p.GetHashCode());

            var    a   = new ThreeSum(new int[] { 0, 1, 2, -1, -4 }).Sum(new int[] { 0, 1, 2, -1, -4 });
            string str = "[";
            foreach (var b in a)
            {
                str += "[";
                foreach (var c in b)
                {
                    str += c + ",";
                }
                str += "],";
            }
            str += "]";
            Console.WriteLine(str);

            // new TwoSum()._TwoSum(new [] { 2, 7, 11, 15 }, 9);
            new TwoSum().__TwoSum(new [] { 3, 2, 4 }, 6);
            new _MajorityElement().MajorityElement(new [] { 2, 2, 1, 1, 1, 2, 2 });
            Console.WriteLine(new _FirstMissingPositive().FirstMissingPositive(new [] { 1, 2, 0 }));

            var nodes = new SingleLinkedList <int>();
            var n     = new SingleLinkedListNode <int>(0);
            nodes.InsertToHead(new SingleLinkedListNode <int>(3));
            nodes.InsertToTail(new SingleLinkedListNode <int>(2));
            nodes.InsertToTail(n);
            nodes.InsertToTail(new SingleLinkedListNode <int>(-4));
            // var n = new SingleLinkedListNode<int>(1);
            nodes.HasCycle(nodes.Head);

            var sequenceStack = new SequenceStack <string>(15);
            for (int i = 0; i < 25; i++)
            {
                sequenceStack.Push("数据内容" + (i + 1));
            }
            int count = sequenceStack.Length;
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(sequenceStack.Pop());
            }

            var linkedStack = new LinkedStack <string>(15);
            for (int i = 0; i < 15; i++)
            {
                linkedStack.Push("数据内容" + (i + 1));
            }

            var linkedQueue = new LinkedQueue <string>(5);
            for (int i = 0; i < 5; i++)
            {
                linkedQueue.Enqueue("数据内容" + i);
                Console.WriteLine($"数据容量 capacity={linkedQueue.Capacity} 数据个数 length={linkedQueue.Length}");
            }
            for (int i = 0; i < 5; i++)
            {
                linkedQueue.Dequeue();
                Console.WriteLine($"数据容量 capacity={linkedQueue.Capacity} 数据个数 length={linkedQueue.Length}");
            }
            var circle = new CircleQueue <string>(5);
            for (int i = 0; i < 5; i++)
            {
                circle.Enqueue("数据内容" + i);
                Console.WriteLine($"数据容量 capacity={circle.Capacity} 数据个数 length={circle.Length}");
            }
            for (int i = 0; i < 5; i++)
            {
                var c = circle.Dequeue();
                Console.WriteLine($"数据容量 capacity={circle.Capacity} 数据个数 length={circle.Length}");
            }

            Demonstrations demonstrations = new Demonstrations();
            Console.WriteLine(demonstrations.FibRecursionTail(8, 0, 1));
            Console.WriteLine(demonstrations.Factorial(8) + " 递归:" + demonstrations.FactorialRecursion(8) + " 尾递归:" + demonstrations.FactorialRecursionTail(8, 1));

            BigSort <int> sort   = new BigSort <int>();
            var           source = new [] { 1, 2, 3, 6, 2, 4, 8, 0, 11, 2, 3, 6, 3, 1 };
            sort.MergeSort(source);
            Console.WriteLine(source);
            var sources = new [] { 4, 5, 6, 1, 2, 3 };
            // sort.BublleSort(sources);
            // sort.BublleSortOptimize(sources);
            // sort.InsertionSort(sources);
            sort.SelectionSort(new [] { 1, 2, 3, 7, 1, 2, 3, 5, 6, 7, 10, 9, 6, 5, 4, 2 });

            var sqrt   = new SqrtX();
            int sqrted = int.MaxValue;
            Console.WriteLine($"{sqrted} 的平方根整数值为:{sqrt.Sqrt(sqrted)}");

            LRUBaseLinkedHashTable <int, string> hashtables = new LRUBaseLinkedHashTable <int, string>(5);
            //insert
            for (int i = 0; i < hashtables.Capacity; i++)
            {
                hashtables.Add(i, "marson" + i);
            }
            //print
            hashtables.Print();
            Console.WriteLine();
            //random visitor
            var random = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < hashtables.Capacity; i++)
            {
                var r = random.Next(0, 3);
                var v = hashtables.GetValue(r);
                Console.WriteLine($"visit key:{v}");
                hashtables.Print();
            }

            ReverseString rs = new ReverseString();
            var           s  = new [] { '\'', '\\', '{' };
            rs.Reverse(s);
            Console.WriteLine("Reverse:" + string.Join(' ', s));

            BinaryTree <int> bt = new BinaryTree <int>();
            bt.Insert(16);
            bt.Insert(14);
            bt.Insert(20);
            bt.Insert(18);
            bt.Insert(19);
            bt.Insert(23);
            Console.WriteLine("找到的值:" + bt.Find(19).Value);
            bt.Delete(20);
            Console.WriteLine("删除含有两个子节点的节点");

            HeadSort <int> hs = new HeadSort <int>();
            Random         rd = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < 10; i++)
            {
                hs.Insert(rd.Next(100));
            }
        }