Exemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Deleting element from the n-position

        public void remove_elements_at(long pos)
        {
            if ((pos < 0) || (pos > this.amount_of_elements))
            {
                throw new IndexOutOfRangeException();
            }
            //return;

            // Check if we exceeds bounds of array

            else
            {
                Bidilist_elements <T> wp = this.start;
                for (long i = 0; i < pos; i++)
                {
                    wp = wp.getNext();
                }
                if (wp != this.start)
                {
                    wp.getPrev().setNext(wp.getNext());
                }
                if (wp != this.end)
                {
                    wp.getNext().setPrev(wp.getPrev());
                }

                if (wp == this.start)
                {
                    this.start = this.start.getNext();
                }
                if (wp == this.end)
                {
                    this.end = this.end.getPrev();
                }

                this.amount_of_elements--;
            }
        }
Exemplo n.º 2
0
        // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Method of getting new list, starting from the last element
        public Bilist <T> new_List_from_end(long N)
        {
            Bilist <T> reverse_list = new Bilist <T>();

            if (N > this.amount_of_elements)
            {
                return(null);
            }

            Bidilist_elements <T> WP = this.end;

            for (long i = 0; i < N; i++)
            {
                T clo = (T)WP.getData().Clone();
                reverse_list.add_element_start(clo);
                WP = WP.getPrev();
            }
            return(reverse_list);
        }