示例#1
0
 public static void compress() {
   char run = 0;
   boolean old = false;
   while (!BinaryStdIn.isEmpty()) {
     boolean b = BinaryStdIn.readBoolean();
     if (b != old) {
       BinaryStdOut.write(run, lgR);
       run = 1;
       old = !old;
     } else {
       if (run == R - 1) {
         BinaryStdOut.write(run, lgR);
         run = 0;
         BinaryStdOut.write(run, lgR);
       }
       run++;
     }
   }
   BinaryStdOut.write(run, lgR);
   BinaryStdOut.close();
 }