模拟HashSet
2017-01-12 18:02
253 查看
package chain; /** * 单链表 节点(Map中的Entry<K,V>) * * @author sd * */ public class Node_Single { public String key;// 节点的值 public Node_Single next;// 指向下一个的指针 public Node_Single(String key) {// 初始化head this.key = key; this.next = null; } public Node_Single(String key, Node_Single next) { this.key = key; this.next = next; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public Node_Single getNext() { return next; } public void setNext(Node_Single next) { this.next = next; } @Override public String toString() { return "Node_Single [key=" + key + ", next=" + next + "]"; } }
package chain; import java.io.IOException; import net.sf.json.JSONArray; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; /** * 单链表(单个数据组的单链表) * * @author sd * */ public class SingleList { transient static Node_Single[] table = new Node_Single[1]; static int bucketIndex = 0;// 索引 public static ObjectMapper mapper = new ObjectMapper(); /** * 添加一个元素 * * @param node */ public void addTolist(String key) { Node_Single e = table[bucketIndex]; table[bucketIndex] = new Node_Single(key, e); } public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException { SingleList sin = new SingleList(); sin.addTolist("1"); sin.addTolist("2"); System.out.println(table[0]); System.out.println(JSONArray.fromObject(table)); System.out.println(mapper.writeValueAsString(table)); } }结果
Node_Single [key=2, next=Node_Single [key=1, next=null]] SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/E:/workspace/Test1/WebContent/WEB-INF/lib/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/E:/workspace/Test1/WebContent/WEB-INF/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] [{"key":"2","next":{"key":"1","next":null}}] [{"key":"2","next":{"key":"1","next":null}}]
相关文章推荐
- eclipse 转idea快捷键
- 开发多线程篇—GCD的常见用法
- IMF spark 正则表达式 统计apache log 日志
- table-cell布局
- CentOS 安装 Mogodb(在线 && 离线)
- Java中Json转换Bean对象并忽略大小写!
- jquery选择器说明
- 1151: 零起点学算法58——开灯问题
- 【SSH网上商城项目实战09】添加和更新商品类别功能的实现
- 重新认识HBase,Cassandra列存储——本质是还是行存储,只是可以动态改变列(每行对应的数据字段)数量而已,当心不是parquet
- PostgreSQL死锁处理
- 苹果App部署HTTPS进行在线下载安装
- shape
- 使用append出的标签用on绑定事件无效的解决方法
- <转> Spark 线性代数库 Breeze API 详解
- 特殊权限之sgid
- Laravel 5 Failed opening required bootstrap/../vendor/autoload.php 报错
- 浅析Spring AOP源码(十六) 分析ProxyFactory
- android_77_fragment_support向下兼容
- CALayer之mask属性-遮罩