예제 #1
0
        public bool MoveNext()
        {
            _currentMember = _nextMember;
            if (_currentMember != null)
            {
                _nextMember = _nextMember.GetNext();
            }

            return(_currentMember != null);
        }
예제 #2
0
        public void Reset()
        {
            while (_currentMember.GetPrev() != null)
            {
                _currentMember = _currentMember.GetPrev();
            }

            _nextMember    = _currentMember;
            _currentMember = null;
        }
예제 #3
0
        public void Print()
        {
            Console.Write("{ ");

            LinkedListMember currentMember = _first;

            while (currentMember != null)
            {
                Console.Write(currentMember.GetData() + " ");
                currentMember = currentMember.GetNext();
            }

            Console.WriteLine("}");
        }
예제 #4
0
        private LinkedListMember GetMember(int index)
        {
            if (index < 0 || index >= _size)
            {
                throw new IndexOutOfRangeException();
            }

            LinkedListMember targetMember = _first;

            for (int i = 0; i < index; i++)
            {
                targetMember = targetMember.GetNext();
            }

            return(targetMember);
        }
예제 #5
0
        public void Remove(int index)
        {
            if (index < 0 || index >= _size)
            {
                throw new IndexOutOfRangeException();
            }

            LinkedListMember targetMember = GetMember(index);

            LinkedListMember prev = targetMember.GetPrev();
            LinkedListMember next = targetMember.GetNext();

            prev?.SetNext(next);
            next?.SetPrev(prev);

            if (index == 0)
            {
                _first = next;
            }

            _size--;
        }
예제 #6
0
        public void Reverse()
        {
            if (_size < 2)
            {
                return;
            }

            LinkedListMember currentMember = _first;
            LinkedListMember newFirst      = null;

            while (currentMember != null)
            {
                LinkedListMember next = currentMember.GetNext();
                currentMember.SetNext(currentMember.GetPrev());
                currentMember.SetPrev(next);

                newFirst      = currentMember;
                currentMember = next;
            }

            _first = newFirst;
        }
예제 #7
0
        public void AddAs(int index, int data)
        {
            LinkedListMember newMember = new LinkedListMember(data);

            if (index < 0 || index > _size)
            {
                throw new IndexOutOfRangeException();
            }

            if (_size == 0)
            {
                _first = newMember;
                _first.SetPrev(null);
                _first.SetNext(null);
            }
            else if (index == 0)
            {
                newMember.SetNext(_first);
                _first.SetPrev(newMember);
                _first = newMember;
            }
            else
            {
                LinkedListMember addAfterMember = GetMember(index - 1);

                LinkedListMember next = addAfterMember.GetNext();

                next?.SetPrev(newMember);
                addAfterMember.SetNext(newMember);

                newMember.SetPrev(addAfterMember);
                newMember.SetNext(next);
            }

            _size++;
        }
예제 #8
0
 public void Clear()
 {
     _size  = 0;
     _first = null;
 }
예제 #9
0
 public void SetNext(LinkedListMember next)
 {
     _next = next;
 }
예제 #10
0
 public void SetPrev(LinkedListMember prev)
 {
     _prev = prev;
 }
예제 #11
0
 public LinkedListEnum(LinkedListMember firstMember)
 {
     _currentMember = null;
     _nextMember    = firstMember;
 }