private PersistentArrayNode Push(PersistentArrayNode prevNode, char c) { PersistentArrayNode newNode = new PersistentArrayNode(prevNode); bool move; if (moves.Count > 0) { move = moves.Pop(); if (move) { newNode.Right = this.Push(newNode.Right, c); } else { newNode.Left = this.Push(newNode.Left, c); } } else { newNode.Value = c; } return(newNode); }
public void Append(string s) { foreach (char c in s) { this.Length++; PrepareMoves(this.Length); this.Root = this.Push(this.Root, c); } }
public PersistentArrayNode(PersistentArrayNode prevNode) { if (prevNode != null) { this.Left = prevNode.Left; this.Right = prevNode.Right; this.Value = prevNode.Value; } }
public char Print(int position) { PrepareMoves(position); PersistentArrayNode node = this.Root; bool move; while (moves.Count > 0) { move = moves.Pop(); if (move) { node = node.Right; } else { node = node.Left; } } return(node.Value); }
public PersistentArray(PersistentArray array) { this.Length = array.Length; this.Root = array.Root; }