当前位置:网站首页>符号表
符号表
2022-08-10 05:32:00 【cbys-1357】
符号表
符号表中,键具有唯一性。
应用 | 查找目的 | 键 | 值 |
字典 | 找出单词的释义 | 单词 | 释义 |
图书索引 | 找出某个术语相关的页码 | 术语 | 一串页码 |
网络搜索 | 找出某个关键字对应的网页 | 关键字 | 网页名称 |
代码实现:
public class SymbolTable<Key,Value> {
// 记录头节点
private Node head;
// 记录符号表元素的个数
private int N;
private class Node{
// 键
public Key key;
// 值
public Value value;
// 下一个结点
public Node next;
public Node(Key key,Value value,Node next){
this.key=key;
this.value=value;
this.next=next;
}
}
// 构造方法
public SymbolTable() {
this.head=new Node(null,null,null);
this.N=0;
}
// 返回符号表中元素的个数
public int size() {
return N;
}
// 向符号表中添加元素
public void put(Key key,Value value) {
Node n=head;
// 遍历符号表
while(n.next!=null) {
n=n.next;
// 如果键在链表中存在,则只需要改变key所对应值
if(n.key.equals(key)) {
n.value=value;
return;
}
}
// 如果不存在,则添加一个新结点(键值对)
Node newNode=new Node(key,value,null);
Node oldfirst=head.next;
head.next=newNode;
newNode.next=oldfirst;
N++;
}
//删除符号表中键为key的键值对
public void delete(Key key) {
Node n=head;
while(n.next!=null) {
if(n.next.key.equals(key)) {
n.next=n.next.next;
N--;
return;
}
n=n.next;
}
}
//从符号表中获取key对应的值
public Value get(Key key) {
Node n=head;
while(n.next!=null) {
n=n.next;
if(n.key.equals(key)) {
return n.value;
}
}
return null;
}
}
边栏推荐
- 常用类 BigDecimal
- ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
- Timer (setInterval) on and off
- cesium add point, move point
- 多表查询 笔记
- cesium 添加点,移动点
- The latest and most complete digital collection sales calendar-07.26
- error in ./node_modules/cesium/Source/ThirdParty/zip.js
- 最新最全的数字藏品发售日历-07.26
- IDEA 项目中设置 Sources Resources 等文件夹
猜你喜欢
Analysis of the investment value of domestic digital collections
【List练习】遍历集合并且按照价格从低到高排序,
ORACLE系统表空间SYSTEM占满无法扩充表空间问题解决过程
文章复现:超分辨率网络-VDSR
matlab中的常用的类型转换
Timer (setInterval) on and off
The latest and most complete digital collection sales calendar-07.26
PCL,VS配置过程中出现:用 _sopen_s 代替 _open, 或用_CRT_SECURE_NO_WARNNINGS错误
深度学习中的学习率调整策略(1)
常用类 String概述
随机推荐
第二次实验
Module build failed TypeError this.getOptions is not a function报错解决方案
2021-07-09
cesium rotate image
cesium listens to map zoom or zoom to control whether the content added on the map is displayed
opencv
利用 crontab 拷贝大文件
事务、存储引擎
Timer (setInterval) on and off
Canal reports Could not find first log file name in binary log index file
Privatisation build personal network backup NextCloud
Batch add watermark to pictures batch scale pictures to specified size
深度学习中数据到底要不要归一化?实测数据来说明!
行盒子的盒模型
网络安全6
操作表 函数的使用
IDEA的database使用教程(使用mysql数据库)
毫米波雷达数据集Scorp使用
你不知道的常规流
Operation table Function usage