Пример #1
0
 public void AddFirst(int value)
 {
     _head = new Node1(value)
     {
         Next = _head
     };
 }
Пример #2
0
        public int DelPosition(int position)
        {
            if (position <= 0 || position > Size() || Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var   value    = 0;
            var   index    = 0;
            Node1 previous = null;
            var   current  = _head;

            while (current != null)
            {
                if (index == position)
                {
                    if (previous != null)
                    {
                        previous.Next = current.Next;
                    }
                    else
                    {
                        _head = _head.Next;
                    }

                    value = current.Value;
                }
                previous = current;
                current  = current.Next;
                index++;
            }

            return(value);
        }
Пример #3
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _head.Value;
            _head = _head.Next;

            return value;
        }
Пример #4
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _head.Value;

            _head = _head.Next;

            return(value);
        }
Пример #5
0
        public void AddLast(int value)
        {
            var node = new Node1(value);
            if (_head == null)
            {
                _head = node;
            }
            else
            {
                var current = _head;
                while (current != null)
                {
                    current = current.Next;
                }

                current.Next = node;
            }
        }
Пример #6
0
        public void AddLast(int value)
        {
            var node = new Node1(value);

            if (_head == null)
            {
                _head = node;
            }
            else
            {
                var current = _head;
                while (current != null)
                {
                    current = current.Next;
                }

                current.Next = node;
            }
        }
Пример #7
0
 public void Clear()
 {
     _head = null;
 }
Пример #8
0
        public int DelPosition(int position)
        {
            if (position <= 0 || position > Size() || Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = 0;
            var index = 0;
            Node1 previous = null;
            var current = _head;

            while (current != null)
            {
                if (index == position)
                {
                    if (previous != null)
                    {
                        previous.Next = current.Next;
                    }
                    else
                    {
                        _head = _head.Next;
                    }

                    value = current.Value;
                }
                previous = current;
                current = current.Next;
                index++;
            }

            return value;
        }
Пример #9
0
 public void Clear()
 {
     _head = null;
 }
Пример #10
0
 public void AddFirst(int value)
 {
     _head = new Node1(value) { Next = _head };
 }