示例#1
0
        public void Add(int data)
        {
            DLinkedListNode travel = head;

            while (travel.next != null)
            {
                travel = travel.next;
            }
            travel.next = new DLinkedListNode(data);
        }
示例#2
0
        public static bool IsPalindrome(DLinkedList li)
        {
            DLinkedListNode travel0 = li.head;
            DLinkedListNode travel1 = li.head;
            int             len     = 0;

            while (travel1.next != null)
            {
                travel1 = travel1.next;
                len++;
            }
            len = (len + 1) / 2;
            for (int i = 0; i < len; i++)
            {
                if (travel0.data != travel1.data)
                {
                    return(false);
                }

                travel0 = travel0.next;
                travel1 = travel1.prev;
            }
            return(true);
        }
示例#3
0
 public DLinkedListNode(int data)
 {
     next      = null;
     prev      = null;
     this.data = data;
 }