public static void expand() {
		String[] st = new String[L];
		int i; // next available codeword value
		
		for (i = 0; i < R; i++) 
			st[i] = "" + (char) i;
		
		st[i++] = ""; // termination codeword
		
		int codeword = BinaryStdIn.readInt(W);
		if (codeword == R) return; // if empty message
		String val = st[codeword];
		
		while(true) {
			BinaryStdOut.write(val);
			
			codeword = BinaryStdIn.readInt(W);
			if (codeword == R) break;
			
			String s = st[codeword];
			
			// tricky case
			if (codeword == i) s = val + val.charAt(0);
			// add string into table
			if (i < L) st[i++] = val + s.charAt(0);
			
			val = s;
		}
		
		BinaryStdOut.close();
	}