Exemplo n.º 1
0
 public void AddFirst(int value)
 {
     _head = new Node1(value)
     {
         Next = _head
     };
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

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

            return value;
        }
Exemplo n.º 4
0
        public int DelFirst()
        {
            if (Size() == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var value = _head.Value;

            _head = _head.Next;

            return(value);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 7
0
 public void Clear()
 {
     _head = null;
 }
Exemplo n.º 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;
        }
Exemplo n.º 9
0
 public void Clear()
 {
     _head = null;
 }
Exemplo n.º 10
0
 public void AddFirst(int value)
 {
     _head = new Node1(value) { Next = _head };
 }