public DoubleCircularList(T item) { m_header = new DoubleNode <T>(item); current = new DoubleNode <T>(); newNode = new DoubleNode <T>(); m_header.SetNext(m_header); m_header.SetPrev(m_header); }
/// <summary> /// Insert used to add an Item anywhere into the list after any given value /// </summary> /// <param name="newItem">New Item being added into the linked list</param> /// <param name="after">After this value the new Item will be added</param> public void Insert(T newItem, T after) { newNode = new DoubleNode<T>(newItem); current = Find(after); newNode.SetNext(current.GetNext()); newNode.SetPrev(current); current.SetNext(newNode); }
/// <summary> /// This method is used to find the last value in the doubly linked list /// </summary> /// <returns>the found node</returns> private DoubleNode<T> FindLast() { current = m_header; while (!(current.GetNext() == null)) { current = current.GetNext(); } return current; }
/// <summary> /// Print all data values in the linked list /// </summary> public void PrintList() { current = m_header; do { Console.WriteLine(current.GetData()); current = current.GetNext(); }while (!(current == m_header)); }
/// <summary> /// This is the same as above but instead prints the list in reverse /// </summary> public void PrintReverse() { current = FindLast(); while (!(current.GetPrev() == null)) { Console.WriteLine(current.GetData().ToString()); current = current.GetPrev(); } }
/// <summary> /// Print all data values in the linked list /// </summary> public void PrintList() { current = m_header; while (!(current.GetNext() == null)) { Console.WriteLine(current.GetNext().GetData().ToString()); current = current.GetNext(); } }
/// <summary> /// Same concept as above Find except that it finds the previous node to the one in Item /// </summary> /// <param name="Item">Genreic field used in the search</param> /// <returns>return node</returns> private DoubleNode <T> FindPrevious(T Item) { current = m_header; do { current = current.GetNext(); }while (!(current.GetNext() == m_header) && (!current.GetNext().GetData().Equals(Item))); return(current); }
/// <summary> /// This method is used to find the last value in the doubly linked list /// </summary> /// <returns>the found node</returns> private DoubleNode <T> FindLast() { current = m_header; do { current = current.GetNext(); }while (!(current.GetNext().Equals(m_header))); return(current); }
/// <summary> /// This method will remove the given Item from the list and ajust all links /// </summary> /// <param name="Item">Item to be removed</param> public void Remove(T Item) { DoubleNode<T> p = Find(Item); if (!(current.GetNext() == null)) { p.GetPrev().SetNext(p.GetNext()); p.GetNext().SetPrev(p.GetPrev()); p.SetNext(null); p.SetPrev(null); } }
/// <summary> /// This method will remove the given Item from the list and ajust all links /// </summary> /// <param name="Item">Item to be removed</param> public void Remove(T Item) { DoubleNode <T> p = FindPrevious(Item); if (!(p.GetNext() == m_header)) { p.GetPrev().SetNext(p.GetNext()); p.GetNext().SetPrev(p.GetPrev()); p.SetNext(null); p.SetPrev(null); } }
/// <summary> /// Method used to add node to end of the linked list /// </summary> /// <param name="newItem">The Item being added to the end of the linked list</param> public void AddToEnd(T newItem) { current = m_header; newNode = new DoubleNode<T>(newItem); while (!(current.GetNext() == null)) { current = current.GetNext(); } current.SetNext(newNode); newNode.SetPrev(current); }
/// <summary> /// This private method is used to run a search through the linked list to find an object specified in Item /// </summary> /// <param name="Item">Generic object that is searched for in the Linked list</param> /// <returns>Generic node used in other methods</returns> private DoubleNode<T> Find(T Item) { current = m_header; while ((!(current.GetData().Equals(Item)) && (!(current.GetNext() == null)))) { current = current.GetNext(); } if (!current.GetData().Equals(Item)) { current = null; } return current; }
public DoubleNode(T Data) { this.Data = Data; Next = null; Prev = null; }
/// <summary> /// Constructers /// </summary> public DoubleNode() { Data = default(T); Next = null; Prev = null; }
/// <summary> /// Sets the next linked node /// </summary> /// <param name="next">The object used to be set as next</param> public void SetNext(DoubleNode <T> next) { Next = next; }
/// <summary> /// Sets the previous object that is linked to the node /// </summary> /// <param name="Prev">The object to be set as previous</param> public void SetPrev(DoubleNode <T> Prev) { this.Prev = Prev; }
public DoublyLinkedList(T item) { m_header = new DoubleNode<T>(item); current = new DoubleNode<T>(); newNode = new DoubleNode<T>(); }