예제 #1
0
        private LinkedListEnds <T> ReverseList <T>(Node <T> node)
        {
            if (node == null)
            {
                return(null);
            }

            Node <T> reverse = CopyNode(node);

            if (node.Next == null)
            {
                LinkedListEnds <T> ends = new LinkedListEnds <T>();
                ends.Head = CopyNode(node);
                return(ends);
            }

            LinkedListEnds <T> listEnds = ReverseList(node.Next);

            if (listEnds.Tail == null)
            {
                listEnds.Head.Next = reverse;
                listEnds.Tail      = reverse;
            }
            else
            {
                listEnds.Tail.Next = reverse;;
                listEnds.Tail      = reverse;
            }

            return(listEnds);
        }
예제 #2
0
        public bool IsPalindrome(Node <char> node)
        {
            LinkedListEnds <char> reverse     = ReverseList(node);
            Node <char>           reverseNode = reverse.Head;

            while (node != null)
            {
                node        = GetNextLetterNode(node);
                reverseNode = GetNextLetterNode(reverseNode);

                int val1 = GetCharacterValue(node.Data);
                int val2 = GetCharacterValue(reverseNode.Data);

                if (val1 != val2)
                {
                    return(false);
                }

                node        = node.Next;
                reverseNode = reverseNode.Next;
            }

            return(true);
        }