Skip to content

Commit

Permalink
采用树来进行集合的编写
Browse files Browse the repository at this point in the history
  • Loading branch information
Xikl committed Nov 12, 2018
1 parent ad17fea commit db41978
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/ximo/datastructuresinaction/set/BSTSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ximo.datastructuresinaction.set;

import com.ximo.datastructuresinaction.bst.BinarySearchTree;

/**
* 用树来实现链表
* @author Ximo
* @date 2018/11/12 21:31
*/
public class BSTSet<E extends Comparable<E>> implements Set<E> {

private BinarySearchTree<E> binarySearchTree = new BinarySearchTree<>();

@Override
public void add(E e) {
binarySearchTree.add(e);
}

@Override
public void remove(E e) {
binarySearchTree.remove(e);
}

@Override
public boolean contains(E e) {
return binarySearchTree.contains(e);
}

@Override
public int getSize() {
return binarySearchTree.getSize();
}

@Override
public boolean isEmpty() {
return binarySearchTree.isEmpty();
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/ximo/datastructuresinaction/set/Set.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ximo.datastructuresinaction.set;

/**
* @author Ximo
* @date 2018/11/12 21:27
*/
public interface Set<E> {

void add(E e);

void remove(E e);

boolean contains(E e);

int getSize();

boolean isEmpty();


}

0 comments on commit db41978

Please sign in to comment.