/// <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; } }
/// <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++; }
/// <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); }
/// <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); }
/// <summary> /// Push the supplied node onto this list. /// </summary> public void Push(SimpleLinkedListNode <T> node) { node.Next = head; head = node; _count++; }