コード例 #1
0
 /// <summary>
 /// Push all items of the supplied list on to this one.
 /// </summary>
 /// <param name="list"></param>
 public void Push(SimpleLinkedList <T> list)
 {
     while (list.head != null)
     {
         SimpleLinkedListNode <T> next = list.head.Next;
         list.head.Next = null;
         Push(list.head);
         list.head = next;
     }
 }
コード例 #2
0
        /// <summary>
        /// Push the value onto the head of this list.
        /// </summary>
        public void Push(T value)
        {
            SimpleLinkedListNode <T> newHead = new SimpleLinkedListNode <T>(value)
            {
                Next = head
            };

            head = newHead;
            _count++;
        }
コード例 #3
0
        /// <summary>
        /// Return a copy of the entire list.
        /// </summary>
        /// <returns></returns>
        public List <T> PeekAll()
        {
            List <T> list = new List <T>(Count);
            SimpleLinkedListNode <T> pointer = head;

            while (pointer != null)
            {
                list.Add(pointer.Value);
                pointer = pointer.Next;
            }
            return(list);
        }
コード例 #4
0
 /// <summary>
 /// Pop the head off of the list.
 /// </summary>
 public bool Pop(out T value)
 {
     if (head != null)
     {
         SimpleLinkedListNode <T> prevHead = head;
         head  = prevHead.Next;
         value = prevHead.Value;
         _count--;
         return(true);
     }
     value = default(T);
     return(false);
 }
コード例 #5
0
 /// <summary>
 /// Push the supplied node onto this list.
 /// </summary>
 public void Push(SimpleLinkedListNode <T> node)
 {
     node.Next = head;
     head      = node;
     _count++;
 }