跳表在Java中的实现( 二 )

getUp() {return up;}public void setUp(NodeKeyValue up) {this.up = up;}public NodeKeyValue getDownList() {return down;}public void setDown(NodeKeyValue down) {this.down = down;}public NodeKeyValue getNext() {return next;}public void setNext(NodeKeyValue next) {this.next = next;}public NodeKeyValue getPrevious() {return previous;}public void setPreviousVal(NodeKeyValue previous) {this.previous = previous;}}public static void main(String[] args) {SkipListJava skip = new SkipListJava<>();for (int i = 20; i < 35; i++) {skip.add(i, String.valueOf(i));}System.out.println(skip);assert skip.listsize() == 10;int count = 0;for (Integer i : skip)assert i.equals(count++);skip.remove(23);System.out.println(skip);skip.remove(25);skip.remove(33);skip.remove(30);System.out.println(skip);skip.remove(28);skip.add(25, "25");System.out.println(skip);assert skip.listsize() == 0;assert skip.empty();}}输出:

跳表在Java中的实现

文章插图
 
我们编写了此代码,用于添加到跳表、在跳表中搜索以及从跳表中删除 。
小结跳表的概念在任何编程语言中都是相同的,它是数据结构中的主要算法之一




推荐阅读