Пример #1
0
        static void Main(string[] args)
        {
            bool isLinkedListTest  = false;
            bool isStringArrayTest = true;

            if (isLinkedListTest)
            {
                SinglyLinkedList sList = new SinglyLinkedList();
                DoublyLinkList   dList = new DoublyLinkList();
                CircularLinkList cList = new CircularLinkList();
                Random           rand  = new Random();
                for (int i = 0; i < 10; i++)
                {
                    var nodeVal = rand.Next(10, 20);
                    sList.AddNewNode(nodeVal.ToString());
                    dList.AddNewNode(nodeVal.ToString());
                    cList.AddNewNode(nodeVal.ToString());
                }
                sList.PrintAllNode();
                sList.ReverseNode();
                sList.RemoveDuplicateWithBuffer();
                // sList.RemoveDuplicateWithoutBuffer();
            }
            if (isStringArrayTest)
            {
                ShiftCharacterKpositions shiftCharacter = new ShiftCharacterKpositions();

                shiftCharacter.SiftByK("abnish", 2);

                StringHasUniqueChar stringHasUniqueChar = new StringHasUniqueChar();
                stringHasUniqueChar.StringHasUniqueCharacter("aba");

                CheckPermutation checkPermutation = new CheckPermutation();
                checkPermutation.CheckStringPermutation("abnish", "shabnI");
                ReplaceSpace replaceSpace = new ReplaceSpace();
                replaceSpace.ReplaceSpaceWithPercent20("abnish kumar choudhary   ");

                OneAwayString oneAwayString = new OneAwayString();
                oneAwayString.CheckOneAwayString("abnish", "abnis");
                oneAwayString.CheckOneAwayString("abnish", "abnish");
                oneAwayString.CheckOneAwayString("abnish", "sanjeet");
            }
            Console.ReadKey();
        }
Пример #2
0
        public void Test()
        {
            CircularLinkList <int> list = new CircularLinkList <int>();

            Assert.Equal(0, list.Length);
            Assert.Null(list.Rear);

            // 1 <- 2 <- 3 <- 4
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            Assert.Equal(4, list.Length);
            Assert.Equal(2, list[1]);

            // 1 <- 2  <- 3 <- 4
            // 1 <- 20 <- 3 <- 4
            list[1] = 20;
            Assert.Equal(4, list.Length);
            Assert.Equal(20, list[1]);

            // 1 <- 20      <- 3 <- 4
            // 1 <- 20 <- 5 <- 3 <- 4
            list.Insert(2, 5);
            Assert.Equal(5, list.Length);
            Assert.Equal(5, list[2]);
            Assert.Equal(3, list[3]);

            // 1 <- 20 <- 5 <- 3 <- 4
            //      20 <- 5 <- 3 <- 4
            list.RemoveAt(0);
            Assert.Equal(4, list.Length);
            Assert.Equal(20, list[0]);

            // 20 <- 5 <- 3 <- 4
            // 20 <- 5      <- 4
            list.RemoveAt(2);
            Assert.Equal(3, list.Length);
            Assert.Equal(4, list[2]);

            list.Clear();
            Assert.Equal(0, list.Length);
            Assert.Null(list.Rear);
        }