public T this[int _position] { get { DoublyNode <T> temp = this.head; for (int i = 0; i < _position; ++i) { temp = temp.Next; } return(temp.Data); } }
public bool Contains(T data) { DoublyNode <T> current = head; while (current != null) { if (current.Data.Equals(data)) { return(true); } current = current.Next; } return(false); }
public void AddTail(T data) // checkt it! { if (head == null) { AddHead(data); } else { DoublyNode <T> temp = new DoublyNode <T>(data); tail.Next = temp; temp.Prev = tail; tail = temp; length += 1; } }
public void RemoveHead() // check it! { if (Length <= 0) { return; } head = head.Next; head.Prev = null; if (head == null) { tail = null; } length -= 1; }
public void AddHead(T data) { DoublyNode <T> temp = new DoublyNode <T>(data); if (head == null) { tail = temp; } else { temp.Next = head; head.Prev = temp; } head = temp; length++; }
public void RemoveTail() { if (Length <= 0) { return; } tail = tail.Prev; tail.Next = null; length -= 1; if (tail == null) { head = null; } }
private int length; // кол-во элементов public void Add(T data) { DoublyNode <T> temp = new DoublyNode <T>(data); if (head == null) { head = temp; } else { tail.Next = temp; temp.Prev = tail; } tail = temp; length += 1; }
public int GetIndex(T data) { DoublyNode <T> current = head; int i = -1; while (current != null) { i += 1; if (current.Data.Equals(data)) { return(i); } else { current = current.Next; } } return(-1); }
public void InsertBefore(T beforeEl, T addElement) { if (Contains(beforeEl)) { DoublyNode <T> current = head; DoublyNode <T> temp = new DoublyNode <T>(addElement); while (current != null) { if (current.Data.Equals(beforeEl)) { if (current.Prev == null) { AddHead(addElement); current = null; } else { temp.Next = current; temp.Prev = current.Prev; current.Prev = temp; temp.Prev.Next = temp; current = null; length++; } } else { current = current.Next; } } } else { AddHead(addElement); } }
public void Clear() { head = null; tail = null; length = 0; }
public DoublyNode(T data) { Data = data; Next = null; Prev = null; }