Example #1
0
        public static bool IsPalindrome(SLinkedList li)
        {
            Stack stack = new Stack();

            stack.Push(li.head);
            SLinkedListNode travel = li.head;

            while (travel.next != null)
            {
                travel = travel.next;
                stack.Push(travel);
            }

            int len = (stack.Count + 1) / 2;

            travel = li.head;
            for (int i = 0; i < len; i++)
            {
                if (stack.Pop() != travel)
                {
                    return(false);
                }
                travel = travel.next;
            }
            return(true);
        }
Example #2
0
        public void Add(int data)
        {
            SLinkedListNode travel = head;

            while (travel.next != null)
            {
                travel = travel.next;
            }
            travel.next = new SLinkedListNode(data);
        }
Example #3
0
 public SLinkedListNode(int data)
 {
     next      = null;
     this.data = data;
 }