-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/ximo/datastructuresinaction/set/BSTSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
src/main/java/com/ximo/datastructuresinaction/set/Set.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
} |