Sha256: db730ed7b5b31846fb91b04cceb7ed55f22d99f4b00d3ad07976282352466efb
Contents?: true
Size: 1.12 KB
Versions: 396
Compression:
Stored size: 1.12 KB
Contents
public class Deque<T> { private Element head; public void Push(T value) { if (head == null) { head = new Element(value); } else { var last = head.Next; var e = new Element(value, last, head); last.Prev = e; head.Next = e; } } public T Pop() { head = head.Next; return Shift(); } public void Unshift(T value) { Push(value); head = head.Next; } public T Shift() { var value = head.Value; var last = head.Next; if (last == head) head = null; else { last.Prev = head.Prev; head.Prev.Next = last; head = head.Prev; } return value; } private class Element { public readonly T Value; public Element Next; public Element Prev; public Element(T value, Element next = null, Element prev = null) { Value = value; Next = next ?? this; Prev = prev ?? this; } } }
Version data entries
396 entries across 396 versions & 1 rubygems