public Node ReadTrie() { bool isLeaf = BinaryStdIn.ReadBoolean(); if (isLeaf) { return(new Node(BinaryStdIn.ReadChar(), -1, null, null)); } return(new Node('\0', -1, ReadTrie(), ReadTrie())); }
public void Expand() { Node root = ReadTrie(); int n = BinaryStdIn.ReadInt(); for (int i = 0; i < n; i++) { Node x = root; while (!x.IsLeaf()) { x = BinaryStdIn.ReadBoolean() ? x.right : x.left; BinaryStdOut.Write(x.ch); } } BinaryStdOut.Close(); }
public void Expand() { string[] st = new string[l]; int i; for (i = 0; i < r; i++) { st[i] = "" + i; } st[i++] = ""; int codeword = BinaryStdIn.ReadInt(w); if (codeword == r) { return; } string val = st[codeword]; while (true) { BinaryStdOut.Write(val); codeword = BinaryStdIn.ReadInt(w); if (codeword == r) { break; } string s = st[codeword]; if (i == codeword) { s = val + val[0]; } if (i < l) { st[i++] = val + s[0]; } val = s; } BinaryStdOut.Close(); }