MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / encode

Method encode

LabEnv/10Lab/MoveToFront.java:20–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19 // apply move-to-front encoding, reading from standard input and writing to standard output
20 public static void encode() {
21 char[] index2Char = init();
22 while (!BinaryStdIn.isEmpty()) {
23 char c = BinaryStdIn.readChar(8);
24
25 int idx = 0;
26 for (; idx < R; idx++)
27 if (index2Char[idx] == c) break;
28 for (int i = idx; i > 0; i--)
29 index2Char[i] = index2Char[i - 1];
30 index2Char[0] = c;
31
32 BinaryStdOut.write(idx, 8);
33 }
34 BinaryStdOut.close();
35 }
36
37 // apply move-to-front decoding, reading from standard input and writing to standard output
38 public static void decode() {

Callers 1

mainMethod · 0.95

Calls 2

initMethod · 0.95
isEmptyMethod · 0.45

Tested by

no test coverage detected