Exemple #1
0
            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);
            }
Exemple #2
0
 public void Append(string s)
 {
     foreach (char c in s)
     {
         this.Length++;
         PrepareMoves(this.Length);
         this.Root = this.Push(this.Root, c);
     }
 }
Exemple #3
0
 public PersistentArrayNode(PersistentArrayNode prevNode)
 {
     if (prevNode != null)
     {
         this.Left  = prevNode.Left;
         this.Right = prevNode.Right;
         this.Value = prevNode.Value;
     }
 }
Exemple #4
0
            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);
            }
Exemple #5
0
 public PersistentArray(PersistentArray array)
 {
     this.Length = array.Length;
     this.Root   = array.Root;
 }