Пример #1
0
 /// <summary>
 /// Add function for an empty stack.
 /// </summary>
 /// <param name="value">The new object</param>
 protected void AddEmpty(T value)
 {
     Count   = 1;
     Last    = new CircularArrayNode <T>(value);
     First   = Last;
     addFunc = AddPartial;
 }
Пример #2
0
 /// <summary>
 /// Returns the element at the given relative index. If the given item is not
 /// available, this method will return null. The relative index starts at 0
 /// for the oldest element in the CircularArrayNode.
 /// </summary>
 /// <param name="index">The relative index of the element.</param>
 /// <returns>value</returns>
 public T Get(int index)
 {
     if (-1 < index && index < Count)
     {
         CircularArrayNode <T> node = First.Get(index);
         return(default(CircularArrayNode <T>) == node ? default(T) : node.Value);
     }
     throw new ArgumentOutOfRangeException(String.Format("Requested index {0} exceeds array length.", index));
 }
Пример #3
0
        /// <summary>
        /// Add function for stack contain 1<= n < Capacity elements.
        /// </summary>
        /// <param name="value">The new object</param>
        protected void AddPartial(T value)
        {
            Last.Child = new CircularArrayNode <T>(value);
            Last       = Last.Child;
            Count++;

            if (Count == Capacity)
            {
                addFunc = AddFull;
            }
        }
Пример #4
0
 /// <summary>
 /// Add function for a full stack.
 /// </summary>
 /// <param name="value">The new object</param>
 protected void AddFull(T value)
 {
     Last.Child = new CircularArrayNode <T>(value);
     Last       = Last.Child;
     First      = First.Child;
 }