zoukankan      html  css  js  c++  java
  • 符号表

    符号表,有时候被称为字典,类似于那本将单词释义按照字母排列顺序排列起来的历史悠久的参考书!

    符号表,最主要的目的是将一个键和一个值进行联系,实现的重点是其使用的数据结构,put()和get()方法

    接下来是一个测试用例,FrequendCounter用例会从标准的输入中得到一列字符串,并且记录每个(长度至少达到指定的阈值)字符串的出现次数,然后遍历所有键,找出出现频率最高的键

     1 public class FrequentCounter
     2 {
     3    public static void  main (String []args)
     4    {
     5      int minlen=Integer.parseInt(args[]);
     6      ST<String,Integer> st=new ST<String,Integer>;
     7     while(!StdIn.isEmpty())
     8    {
     9      String word=StdIn.readString();
    10     if(word.length()<minlen)  continue //忽略较短的单词 
    11     if (!st.contains(word()) st.put(word,1);
    12     else  st.put(word,st,get(word)+1);
    13     }
    14     //找出出现频率最高的单词
    15     String max=“”;
    16     st.put(max,0)
    17     for(String word : st.keys())//遍历
    18     if(st.get(word)>st.get(max))
    19     max=word;
    20    stdOut.println(max+"  "+st.get(max));
    21   }
    22 }
  • 相关阅读:
    知识点整理
    NGINX 内存池有感
    NGINX怎样处理惊群的
    NGINX 定时器
    制作linux内核安装包
    ES6变量的解构赋值
    jquery uploadify上传插件用法心得
    【转贴】J2EE中的13种技术规范
    【转帖】Servlet 3.0 新特性详解
    汉诺塔问题的一个C#实现
  • 原文地址:https://www.cnblogs.com/lujun1949/p/5499528.html
Copyright © 2011-2022 走看看