public void Forth() { if (m_node != null) { m_node = m_node.m_next; } }
private static void Calculate(LStack stack, LStack postfix) { x += 1; Console.Write("\n" + x + " : "); Console.Write("\n Stack = "); DListNode itr1 = stack.m_head; for (int i = 1; i <= stack.m_count; i++) { Console.Write(itr1.m_data); itr1 = itr1.m_next; if (itr1 == null) { break; } } Console.Write("\n Postfix = "); DListNode itr2 = postfix.m_head; for (int i = 1; i <= postfix.m_count; i++) { Console.Write(itr2.m_data); itr2 = itr2.m_next; if (itr2 == null) { break; } } }
public void Start() { if (m_list != null) { m_node = m_list.m_head; } }
public DLinkList() { DListNode itr = m_head; DListNode next; while (itr != null) { next = itr.m_next; itr = null; itr = next; } }
public void Prepend(string p_data) { if (m_tail == null) { m_tail = m_head = new DListNode(p_data); } else { m_head.InsertBefore(p_data); m_head = m_head.m_previous; } m_count++; }
public void Append(string p_data) { if (m_head == null) { m_head = m_tail = new DListNode(p_data); } else { m_tail.InsertAfter(p_data); m_tail = m_tail.m_next; } m_count++; }
private static void Result(LStack postfix) { Console.Write("\n\nResult Postfix = "); DListNode itr1 = postfix.m_head; for (int i = 1; i <= postfix.m_count; i++) { Console.Write(itr1.m_data); itr1 = itr1.m_next; if (itr1 == null) { break; } } }
public DListNode InsertBefore(string p_data) { DListNode newNode = new DListNode(p_data); newNode.m_previous = m_previous; if (m_previous != null) { m_previous.m_next = newNode; } m_previous = newNode; newNode.m_next = this; return(newNode); }
public DListNode InsertAfter(string p_data) { DListNode newNode = new DListNode(p_data); newNode.m_next = m_next; if (m_next != null) { m_next.m_previous = newNode; } m_next = newNode; newNode.m_previous = this; return(newNode); }
public void RemoveTail() { DListNode node = null; if (m_tail != null) { node = m_tail.m_previous; m_tail.m_data = null; m_tail = node; if (m_tail == null) { m_head = null; } m_count--; } }
public void RemoveHead() { DListNode node = null; if (m_head != null) { node = m_head.m_next; m_head.m_data = null; m_head = node; if (m_head == null) { m_tail = null; } m_count--; } }
public void Insert(DListIterator p_iterator, string p_data) { if (p_iterator.m_list != this) { return; } if (p_iterator.m_node != null) { p_iterator.m_node.InsertAfter(p_data); if (p_iterator.m_node == m_tail) { m_tail = p_iterator.m_node.m_next; } m_count++; } else { Append(p_data); } }
public void Remove(DListIterator p_iterator, DListNode node) { if (p_iterator.m_list != this) { return; } if (p_iterator.m_node == null) { return; } if (p_iterator.m_node == m_head) { p_iterator.Forth(); RemoveHead(); } else { while (node.m_next != p_iterator.m_node) { node = node.m_next; } p_iterator.Forth(); if (node.m_next == m_tail) { m_tail = node; } node.m_next = null; node.m_next = p_iterator.m_node; } m_count--; }
public DListNode(string value) { m_data = value; m_next = null; m_previous = null; }
public DListIterator(DLinkList p_list = null, DListNode p_node = null) { m_list = p_list; m_node = p_node; }