public void Add(T value)
 {
     // First insertion
     if (this.head == null)
     {
         this.head = new SimpleNode <T>(value);
         this.tail = this.head;
         this.Count++;
     }
     else
     {
         this.tail.Next = new SimpleNode <T>(value);
         this.tail      = this.tail.Next;
         this.Count++;
     }
 }
        public T this[int index]
        {
            get
            {
                int            count = -1;
                SimpleNode <T> currentNode;

                currentNode = this.head;
                count++;
                try
                {
                    while (count < index)
                    {
                        count++;
                        currentNode = currentNode.Next;
                    }
                    return(currentNode.Value);
                }
                catch (NullReferenceException)
                {
                    throw new IndexOutOfRangeException();
                }
            }
            set
            {
                int            count = -1;
                SimpleNode <T> currentNode;

                currentNode = this.head;
                count++;
                try
                {
                    while (count < index)
                    {
                        count++;
                        currentNode = currentNode.Next;
                    }
                    SimpleNode <T> nextNode = currentNode.Next;
                    currentNode = new SimpleNode <T>(value, nextNode);
                }
                catch (NullReferenceException)
                {
                    throw new IndexOutOfRangeException();
                }
            }
        }
 public SimpleLinkedList()
 {
     this.head = null;
     this.tail = null;
 }
 public void Clear()
 {
     this.tail  = this.head = null;
     this.Count = 0;
 }
コード例 #5
0
 public SimpleNode(T value, SimpleNode <T> next)
 {
     this.Value = value;
     this.Next  = next;
 }