public void AddAtStart(T value) { head = new SinglyLinkedNode <T> { Data = value, Next = head }; size++; }
public T TakeAtStart() { var value = head.Data; head = head.Next; tail.Next = head; size--; return(value); }
public T Pop() { var value = head.Data; head = head.Next; size--; return(value); }
public void Push(T item) { var newNode = new SinglyLinkedNode <T> { Data = item, Next = head }; head = newNode; size++; }
public T TakeAtStart() { if (size > 0) { var nextAfterHead = head.Next; var value = head.Data; head = nextAfterHead; size--; return(value); } return(default(T)); }
public T TakeAtEnd() { T value = tail.Data; var currentNode = head; do { currentNode = currentNode.Next; } while (currentNode.Next.Next != head); currentNode.Next = head; tail = currentNode; size--; return(value); }
public void AddAtEnd(T item) { var newNode = new SinglyLinkedNode <T> { Data = item }; if (size == 0) { head = newNode; tail = newNode; newNode.Next = head; } else { tail.Next = newNode; tail = newNode; newNode.Next = head; } size++; }
public void AddAtEnd(T value) { var node = new SinglyLinkedNode <T> { Data = value, Next = null }; if (head == null) { head = node; } else { var currentNode = head; while (currentNode.Next != null) { currentNode = currentNode.Next; } currentNode.Next = node; } size++; }