zoukankan      html  css  js  c++  java
  • 从Move-To-Front encoding的一个常用问题:把一个元素放到最前面

    在MTF的encoding中,主要就是把要encode的string和symbol table比较,将对应的index保存并把相同的值放到symbol table的最前头。

    eg: string = caaabaa...

           symbol table = 0123abcd...

    则要得到:c0123abd...

    所以主要问题就是把中间一段和c交换位置。

    方法一:2次循环,第一次,在symbol table一个一个比较,找到string这个元素在ST中的ind。第2次,把ST中找到的相同元素一个一个的和前一个交换,知道它换到最前面。

    方法二:msi的做法:只用一次循环,自己画了个step by step才想到。好厉害的for loop写法和temp var的运用。tmpout好机智。

    public static void encode() throws IOException {
            char[] chars = radixList();
            char count, ch, tmpin, tmpout;
            while (!BinaryStdIn.isEmpty()) {
                ch = BinaryStdIn.readChar();
                for (count = 0, tmpout = chars[0]; ch != chars[count]; count++) {
                    tmpin = chars[count];
                    chars[count] = tmpout;
                    tmpout = tmpin;
                }
                chars[count] = tmpout;
                BinaryStdOut.write(count);
                chars[0] = ch;
            }
            BinaryStdOut.close();
        }
  • 相关阅读:
    接口的显式实现和隐式实现
    MVC
    委托
    测试用例(TestCase)
    The remote server returned an error: NotFound.
    事件
    WCF大数据量传输配置
    多态随笔
    领域模型(domain model)
    IQueryable接口和IEnumberable接口
  • 原文地址:https://www.cnblogs.com/gpuasic/p/3813628.html
Copyright © 2011-2022 走看看