Пример #1
0
        public void PrintValues()
        {
            SllNode runner = Head;

            while (runner != null)
            {
                System.Console.WriteLine(runner.Value);
                runner = runner.Next;
            }
        }
Пример #2
0
        public SllNode Find(int value)
        {
            SllNode runner = Head;

            while (runner.Next != null)
            {
                if (runner.Value == value)
                {
                    return(runner);
                }
                runner = runner.Next;
            }
            return(null);
        }
Пример #3
0
        public void Add(int value)
        {
            SllNode newNode = new SllNode(value);

            if (Head == null)
            {
                Head = newNode;
            }
            else
            {
                SllNode runner = Head;
                while (runner.Next != null)
                {
                    runner = runner.Next;
                }
                runner.Next = newNode;
            }
        }
Пример #4
0
 public void Remove()
 {
     if (Head == null)
     {
         return;
     }
     else
     {
         SllNode runner      = Head;
         SllNode runner_next = Head.Next;
         while (runner_next.Next != null)
         {
             runner      = runner_next;
             runner_next = runner_next.Next;
         }
         System.Console.WriteLine(runner.Value);
         runner.Next = null;
     }
 }
Пример #5
0
        public void Reverse()
        {
            SllNode before  = null;
            SllNode current = Head;
            SllNode future  = Head.Next;

            while (future.Next != null)
            {
                SllNode temp = future.Next;

                current.Next = before;
                future.Next  = current;

                before  = current;
                current = future;
                future  = temp;
            }
            future.Next = current;
            Head        = future;
        }
Пример #6
0
        public void RemoveAt(int index)
        {
            SllNode before  = null;
            SllNode current = Head;
            SllNode future  = Head.Next;
            int     counter = 0;

            while (current.Next != null)
            {
                if (counter == index)
                {
                    break;
                }
                before  = current;
                current = future;
                future  = future.Next;
                counter++;
            }
            before.Next = future;
        }
Пример #7
0
 public SLinkedList()
 {
     Head = null;
 }
Пример #8
0
 public SllNode(int value)
 {
     Value = value;
     Next  = null;
 }