public static System.Collections.Generic.LinkedListNode <int> Insert(System.Collections.Generic.LinkedList <int> myLList, int n) { System.Collections.Generic.LinkedListNode <int> firstNode = myLList.First; System.Collections.Generic.LinkedListNode <int> newNode; System.Collections.Generic.LinkedListNode <int> previousNode = null; while (firstNode != null) { if (firstNode.Previous != null) { previousNode = firstNode.Previous; } if ((previousNode != null && previousNode.Value <= n && firstNode.Value >= n)) { newNode = myLList.AddAfter(previousNode, n); break; } else if (firstNode.Value >= n && previousNode == null) { newNode = myLList.AddFirst(n); break; } else if (firstNode.Next == null && firstNode.Value <= n) { newNode = myLList.AddAfter(firstNode, n); break; } firstNode = firstNode.Next; } return(firstNode); }
public static void Delete(System.Collections.Generic.LinkedList <int> myLList, int index) { System.Collections.Generic.LinkedListNode <int> node = myLList.First; int positionList = 0; while (node != null) { if (positionList == index) { myLList.Remove(node); } positionList++; node = node.Next; } }
internal void Invalidate() { list = null; next = null; prev = null; }
void System.Collections.ICollection.CopyTo(Array array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Rank != 1) { throw new ArgumentException(); } if (array.GetLowerBound(0) != 0) { throw new ArgumentException(); } if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (array.Length - index < Count) { throw new ArgumentException(); } T[] tArray = array as T[]; if (tArray != null) { CopyTo(tArray, index); } else { // // Catch the obvious case assignment will fail. // We can found all possible problems by doing the check though. // For example, if the element type of the Array is derived from T, // we can't figure out if we can successfully copy the element beforehand. // Type targetType = array.GetType().GetElementType(); Type sourceType = typeof(T); if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) { throw new ArgumentException(); } object[] objects = array as object[]; if (objects == null) { throw new ArgumentException(); } LinkedListNode <T> node = head; try { if (node != null) { do { objects[index++] = node.item; node = node.next; } while (node != head); } } catch (ArrayTypeMismatchException) { throw new ArgumentException(); } } }
public void Remove(LinkedListNode <T> node) { ValidateNode(node); InternalRemoveNode(node); }
public WeakNode(LinkedListNode <KeyValue> node, WeakTable <TKey, TValue> table) { this.node = node; this.table = table; }
/// <summary>Adds a new node containing the specified value at the end of the <see cref="T:System.Collections.Generic.LinkedList`1" />.</summary> /// <returns>The new <see cref="T:System.Collections.Generic.LinkedListNode`1" /> containing <paramref name="value" />.</returns> /// <param name="value">The value to add at the end of the <see cref="T:System.Collections.Generic.LinkedList`1" />.</param> public LinkedListNode <T> AddLast(T value) { LinkedListNode <T> result = (first != null) ? new LinkedListNode <T>(this, value, first.back, first) : (first = new LinkedListNode <T>(this, value)); count++; version++; return(result); }
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Generic.LinkedList`1" /> class that is empty.</summary> public LinkedList() { syncRoot = new object(); first = null; count = (version = 0u); }
public void Clear() { count = 0; first = null; version++; }
public void Remove(LinkedListNode <T> node) { this.ValidateNode(node); this.InternalRemoveNode(node); }