Example #1
0
        public void Print()
        {
            SLNode Runner = Head;

            while (Runner != null)
            {
                Console.Write($"{Runner.Value} -> ");
                Runner = Runner.Next;
            }
            Console.WriteLine();
        }
Example #2
0
        public bool HasLoop()
        {
            SLNode walker = Head;
            SLNode runner = Head.Next;

            while (walker != null && runner != null && runner.Next != null)
            {
                if (walker == runner)
                {
                    return(true);
                }
                walker = walker.Next;
                runner = runner.Next.Next;
            }
            return(false);
        }
Example #3
0
        public void Reverse()
        {
            SLNode prev = null;
            SLNode curr = Head;
            SLNode next = curr.Next;

            while (next != null)
            {
                curr.Next = prev;
                prev      = curr;
                curr      = next;
                next      = next.Next;
            }
            curr.Next = prev;
            Head      = curr;
        }
Example #4
0
 public void Add(int val)
 {
     if (Head == null)
     {
         Head = new SLNode(val);
     }
     else
     {
         SLNode Runner = Head;
         while (Runner.Next != null)
         {
             Runner = Runner.Next;
         }
         Runner.Next = new SLNode(val);
     }
 }