示例#1
0
        public void Delete(T value)
        {
            SimpleNode <T> temp = _head;

            if (_head == null)
            {
                return;
            }

            do
            {
                if (temp.GetValue().Equals(value))
                {
                    if (temp == _head)
                    {
                        if (Length() == 1)
                        {
                            _head = null;
                        }
                    }
                    temp.SetValue(temp.GetNext().GetValue());
                    if (temp.GetNext() == _head)
                    {
                        _head = temp;
                    }
                    temp.SetNext(temp.GetNext().GetNext());
                    break;
                }
                temp = temp.GetNext();
            }while(temp != _head);
        }
示例#2
0
        public SimpleNode <T> Pop()
        {
            if (_head == null)
            {
                return(null);
            }
            SimpleNode <T> popped = _head;

            _head = _head.GetNext();
            return(popped);
        }
示例#3
0
        public int Size()
        {
            SimpleNode <T> temp   = _head;
            int            result = 0;

            while (temp != null)
            {
                result++;
                temp = temp.GetNext();
            }
            return(result);
        }
示例#4
0
        public int Size()
        {
            SimpleNode <T> current = _head;
            int            result  = 0;

            while (current != null)
            {
                result++;
                current = current.GetNext();
            }
            return(result);
        }
示例#5
0
        public void Delete(T value)
        {
            SimpleNode <T> temp = _head;
            SimpleNode <T> prev = null;

            while (temp != null)
            {
                if (temp.GetValue().Equals(value))
                {
                    if (temp == _head)
                    {
                        _head = temp.GetNext();
                    }
                    else
                    {
                        prev.SetNext(temp.GetNext());
                    }
                    break;
                }
                prev = temp;
                temp = temp.GetNext();
            }
        }
示例#6
0
        public SimpleNode <T> Search(T value)
        {
            SimpleNode <T> temp = _head;

            while (temp != null)
            {
                if (temp.GetValue().Equals(value))
                {
                    break;
                }
                temp = temp.GetNext();
            }
            return(temp);
        }
示例#7
0
        public SimpleNode <T> Peak()
        {
            if (_head == null)
            {
                return(null);
            }

            SimpleNode <T> temp = _head;

            while (temp.HasNext())
            {
                temp = temp.GetNext();
            }
            return(temp);
        }
示例#8
0
        public void Append(T value)
        {
            if (_head == null)
            {
                _head = new SimpleNode <T>(value);
                return;
            }
            SimpleNode <T> temp = _head;

            while (temp.HasNext())
            {
                temp = temp.GetNext();
            }
            temp.SetNext(new SimpleNode <T>(value));
        }
示例#9
0
        public int Length()
        {
            SimpleNode <T> temp = _head;

            if (temp == null)
            {
                return(0);
            }
            int result = 0;

            do
            {
                result++;
                temp = temp.GetNext();
            }while (temp != _head);
            return(result);
        }
示例#10
0
        public SimpleNode <T> Search(T value)
        {
            SimpleNode <T> temp = _head;

            if (_head == null)
            {
                return(null);
            }

            do
            {
                if (temp.GetValue().Equals(value))
                {
                    return(temp);
                }
                temp = temp.GetNext();
            }while(temp != _head);

            return(null);
        }
示例#11
0
        public void Append(T value)
        {
            if (_head == null)
            {
                _head = new SimpleNode <T>(value);
                _head.SetNext(_head);
                return;
            }
            T headCopy = _head.GetValue();
            SimpleNode <T> headNextCopy = _head.GetNext();

            _head.SetValue(value);

            SimpleNode <T> insert = new SimpleNode <T>(headCopy);

            _head.SetNext(insert);
            insert.SetNext(headNextCopy);

            _head = insert;
        }
示例#12
0
        public SimpleNode <T> Dequeue()
        {
            if (_head == null)
            {
                return(null);
            }

            SimpleNode <T> temp = _head;
            SimpleNode <T> prev = null;

            while (temp.HasNext())
            {
                prev = temp;
                temp = temp.GetNext();
            }
            if (prev == null)
            {
                Clear();
                return(temp);
            }
            prev.SetNext(null);
            return(temp);
        }