本文整理汇总了Java中edu.princeton.cs.algs4.BinaryStdOut类的典型用法代码示例。如果您正苦于以下问题:Java BinaryStdOut类的具体用法?Java BinaryStdOut怎么用?Java BinaryStdOut使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryStdOut类属于edu.princeton.cs.algs4包,在下文中一共展示了BinaryStdOut类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inverseTransform
import edu.princeton.cs.algs4.BinaryStdOut; //导入依赖的package包/类
public static void inverseTransform() {
int first = BinaryStdIn.readInt();
char[] t = BinaryStdIn.readString().toCharArray();
char[] sorted = new char[t.length];
int[] count = new int[R+1];
int[] next = new int[t.length];
for (int i = 0; i < t.length; i++)
count[t[i] + 1]++;
for (int r = 0; r < R; r++)
count[r+1] += count[r];
for (int i = 0; i < t.length; i++) {
next[count[t[i]]] = i;
sorted[count[t[i]]++] = t[i];
}
int p = first;
for (int i = 0; i < t.length; i++) {
BinaryStdOut.write(sorted[p]);
p = next[p];
}
BinaryStdOut.close();
}
示例2: encode
import edu.princeton.cs.algs4.BinaryStdOut; //导入依赖的package包/类
public static void encode() {
initCode();
char[] input = BinaryStdIn.readString().toCharArray();
for (int i = 0; i < input.length; i++) {
char index = 0;
while (input[i] != code[index])
index++;
BinaryStdOut.write(index);
while (index > 0) {
code[index] = code[--index];
}
code[0] = input[i];
}
BinaryStdOut.close();
}
示例3: decode
import edu.princeton.cs.algs4.BinaryStdOut; //导入依赖的package包/类
public static void decode() {
initCode();
char[] input = BinaryStdIn.readString().toCharArray();
for (int i = 0; i < input.length; i++) {
int index = (int)input[i];
char output = code[index];
BinaryStdOut.write(output);
while (index > 0) {
code[index] = code[--index];
}
code[0] = output;
}
BinaryStdOut.close();
}
示例4: encode
import edu.princeton.cs.algs4.BinaryStdOut; //导入依赖的package包/类
public static void encode(){
char[] sequence = new char[R];
// Map a char to a position in the sequence array
HashMap<Character, Integer> pointTo = getMappers(sequence);
while (!BinaryStdIn.isEmpty()){
char c = BinaryStdIn.readChar();
int originPos = pointTo.get(c);
BinaryStdOut.write((char)originPos);
moveUp(originPos, sequence, pointTo);
}
BinaryStdOut.close();
}
示例5: decode
import edu.princeton.cs.algs4.BinaryStdOut; //导入依赖的package包/类
public static void decode(){
char[] sequence = new char[R];
HashMap<Character, Integer> pointTo = getMappers(sequence);
while (!BinaryStdIn.isEmpty()) {
char c = BinaryStdIn.readChar();
BinaryStdOut.write(sequence[c]);
moveUp((int)c, sequence, pointTo);
}
BinaryStdOut.close();
}