当前位置:网站首页>符号表
符号表
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;
}
}
边栏推荐
- Bifrost micro synchronous database implementation services across the library data synchronization
- 链读推荐:从瓷砖到生成式 NFT
- cesium 监听地图缩放或放大来控制地图上添加的内容是否展示
- 知识蒸馏论文学习
- The submenu of the el-cascader cascade selector is double-clicked to display the selected content
- impdp 导入数据
- 文章复现:超分辨率网络FSRCNN
- 小程序wx.request简单Promise封装
- 行盒子的盒模型
- view【】【】【】【】
猜你喜欢

多表查询 笔记

Chain Reading|The latest and most complete digital collection sales calendar-08.02

.las转.txt 再转.pcd,编译运行中出现的错误

view【】【】【】【】

IDEA 项目中设置 Sources Resources 等文件夹

ResNet的基础:残差块的原理

国内数字藏品投资价值分析

Set Sources Resources and other folders in the IDEA project

PCL,VS配置过程中出现:用 _sopen_s 代替 _open, 或用_CRT_SECURE_NO_WARNNINGS错误

MySql constraints
随机推荐
R中设置图形参数--函数par()详解
网络安全之防火墙
第二次实验
网络安全5
小程序学习笔记:小程序组件间通信方式
el-cascader级联选择器的子菜单双击两次才显示被选中的内容
常用类 String概述
win12 modify dns script
latex图片排版技巧总结
文本元素
深度学习模型训练前的必做工作:总览模型信息
基本比例尺标准分幅编号流程
去中心化和p2p网络以及中心化为核心的传统通信
图片批量添加水印批量加背景缩放批量合并工具picUnionV4.0
文章复现:超分辨率网络FSRCNN
The latest and most complete digital collection sales calendar-07.26
impdp import data
毫米波雷达基础概念学习
网络安全3
Database Notes Create Database, Table Backup