Skip to content

Commit

Permalink
add Map interface
Browse files Browse the repository at this point in the history
  • Loading branch information
l81893521 committed May 20, 2018
1 parent f055512 commit 2707bfa
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
8. [删除最大元素和最小元素](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/binarySearchTree/HBinarySearchTree.java)
9. [删除任意元素](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/binarySearchTree/IBinarySearchTree.java)

### 集合与映射
### 集合(Set)
1. [集合的基本接口定义](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/set/Set.java)
2. [使用二分搜索树实现集合](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/set/BinarySearchTreeSet.java)
3. [使用链表实现集合](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/set/LinkedListSet.java)

### 映射(Map)
1. [映射的基本接口定义](https://github.com/l81893521/basic-data-structure/blob/master/src/main/java/will/zhang/map/Map.java)
56 changes: 56 additions & 0 deletions src/main/java/will/zhang/map/Map.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package will.zhang.map;

/**
* 映射(Map)的基本接口定义
* @param <K>
* @param <V>
*/
public interface Map<K, V> {

/**
* 添加key和value到Map中
* @param key
* @param value
*/
void add(K key, V value);

/**
* 根据key删除对应的key跟value
* @param key
* @return
*/
V remove(K key);

/**
* 查看该key是否存在于映射中
* @param key
* @return
*/
boolean contains(K key);

/**
* 根据key从映射中查找value
* @param key
* @return
*/
V get(K key);

/**
* 根据key更新映射中对应的value值
* @param key
* @param newValue
*/
void set(K key, V newValue);

/**
* 获取映射的大小
* @return
*/
int getSize();

/**
* 映射是否为空
* @return
*/
boolean isEmpty();
}
8 changes: 8 additions & 0 deletions src/main/java/will/zhang/set/BinarySearchTreeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

/**
* 基于二分搜索树实现的集合
*
* 时间复杂度分析(h=树的高度)
* 增
* add(e) O(logn)
* 查
* contains(e) O(logn)
* 删
* remove(e) O(logn)
* @param <E>
*/
public class BinarySearchTreeSet<E extends Comparable<E>> implements Set<E> {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/will/zhang/set/LinkedListSet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package will.zhang.set;

/**
* 基于链表实现的集合
*
* 时间复杂度分析
* 添加
* add(e) O(n)
* 查
* contains(e) O(n)
* 删
* remove(e) O(n)
* @param <E>
*/
public class LinkedListSet<E> implements Set<E> {

private LinkedList<E> linkedList;
Expand Down

0 comments on commit 2707bfa

Please sign in to comment.