示例#1
0
        public void InsertAt(int position, T value)
        {
            ListNodeClass <T> adding = new ListNodeClass <T>(value);
            int number = 0;

            if (position == 0)
            {
                adding.Next   = Head;
                Head.Previous = adding;
                Head          = adding;
                count++;
            }
            else
            {
                Current = Head;

                while (number <= position)
                {
                    if (number == position)
                    {
                        Result = Current;
                        Result.Previous.Next = adding;
                        adding.Previous      = Result.Previous;
                        Result.Previous      = adding;
                        adding.Next          = Result;
                    }

                    Current = Current.Next;
                    number++;
                }
            }
        }
示例#2
0
        public bool Check(T value)
        {
            ListNodeClass <T> found = FindItem(value);

            if (found == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#3
0
        private ListNodeClass <T> FindItem(T value)
        {
            Current = Head;

            while (Current != null)
            {
                if (Current.Value.Equals(value))
                {
                    return(Current);
                }

                Current = Current.Next;
            }

            return(null);
        }
示例#4
0
        public int IndexItem(T value)
        {
            int position = 0;

            Current = Head;

            while (Current != null && position <= count)
            {
                if (Current.Value.Equals(value))
                {
                    return(position);
                }

                Current = Current.Next;
                position++;
            }
            return(-1);
        }
示例#5
0
        public int AddItem(T value)
        {
            ListNodeClass <T> adding = new ListNodeClass <T>(value);

            if (Head == null)
            {
                Head = adding;
                Tail = Head;
            }

            if (Head != null)
            {
                Tail.Next       = adding;
                adding.Previous = Tail;
                Tail            = adding;
                Tail.Next       = null;
            }

            count++;
            return(count);
        }
示例#6
0
        public void Remove(T value)
        {
            ListNodeClass <T> found = FindItem(value);

            if (found != null)
            {
                ListNodeClass <T> previous = found.Previous;
                ListNodeClass <T> next     = found.Next;

                if (previous == null)
                {
                    Head = next;

                    if (Head != null)
                    {
                        Head.Previous = null;
                    }
                }
                else
                {
                    previous.Next = next;
                }
                if (next == null)
                {
                    Tail = previous;

                    if (Tail != null)
                    {
                        Tail.Next = null;
                    }
                }
                else
                {
                    next.Previous = previous;
                }

                count--;
            }
        }
示例#7
0
        public T Search(T value)
        {
            ListNodeClass <T> found = FindItem(value);

            return(found.Value);
        }