예제 #1
0
        // -------------------------------------------------------------------------------------------

        /*
         * /// <summary>
         * /// Deletes node at the pointed position.
         * /// CANCELLED: If a node is deleted it would impossible to update the traveling stack without workarounds.
         * /// </summary>
         * public void Delete(int Index)
         * {
         *  SimpleNode<Tipo> PointedNode = this.FirstNode,
         *                   PriorNode = null;
         *  int Ind = 0;
         *
         *  while (PointedNode != null)
         *  {
         *      if (Ind == Index)
         *      {
         *          if (FirstNode == PointedNode)
         *              FirstNode = PointedNode.NextNode;
         *          else
         *              PriorNode.NextNode = PointedNode.NextNode;
         *
         *          // Here the traveling stack should be updated, but cannot be done.
         *          return;
         *      }
         *      Ind++;
         *
         *      PriorNode = PointedNode;
         *      PointedNode = PointedNode.NextNode;
         *  }
         *
         *  throw new IndexOutOfRangeException();
         * } */

        // -------------------------------------------------------------------------------------------
        /// <summary>
        /// Returns index of the container node of the supplied object, or -1 if not found.
        /// </summary>
        public int GetIndex(object Data)
        {
            SimpleNode <TData> PointedNode = this.FirstNode;
            int Ind = 0;

            while (PointedNode != null)
            {
                if (Object.Equals(PointedNode.Data, Data))
                {
                    return(Ind);
                }
                Ind++;

                PointedNode = PointedNode.NextNode;
            }

            return(-1);
        }
예제 #2
0
        // -------------------------------------------------------------------------------------------
        /// <summary>
        /// Adds new node at the end.
        /// </summary>
        public void Add(TData Data)
        {
            SimpleNode <TData> Node = new SimpleNode <TData>();

            Node.Data     = Data;
            Node.NextNode = null;

            if (this.LastNode == null)
            {
                this.FirstNode = Node;
                this.Count     = 1;
            }
            else
            {
                this.LastNode.NextNode = Node;
                this.Count++;
            }

            this.LastNode = Node;
        }
예제 #3
0
        // -------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets or sets data of the node at the position of the supplied index.
        /// </summary>
        public TData this[int Index]
        {
            get
            {
                SimpleNode <TData> PointedNode = this.FirstNode;
                int Ind = 0;

                while (PointedNode != null)
                {
                    if (Ind == Index)
                    {
                        return(PointedNode.Data);
                    }
                    Ind++;

                    PointedNode = PointedNode.NextNode;
                }

                throw new IndexOutOfRangeException();
            }
            set
            {
                SimpleNode <TData> PointedNode = this.FirstNode;
                int Ind = 0;

                while (PointedNode != null)
                {
                    if (Ind == Index)
                    {
                        PointedNode.Data = value;
                        return;
                    }
                    Ind++;

                    PointedNode = PointedNode.NextNode;
                }

                throw new IndexOutOfRangeException();
            }
        }