-
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
67 additions
and
0 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/ximo/datastructuresinaction/set/LinkedListSet.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,43 @@ | ||
package com.ximo.datastructuresinaction.set; | ||
|
||
import com.ximo.datastructuresinaction.list.LinkedList; | ||
|
||
/** | ||
* @author Ximo | ||
* @date 2018/11/12 21:50 | ||
*/ | ||
public class LinkedListSet<E> implements Set<E> { | ||
|
||
private LinkedList<E> linkedList; | ||
|
||
public LinkedListSet() { | ||
this.linkedList = new LinkedList<>(); | ||
} | ||
|
||
@Override | ||
public void add(E e) { | ||
if (!linkedList.contains(e)) { | ||
linkedList.addFirst(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void remove(E e) { | ||
linkedList.removeElement(e); | ||
} | ||
|
||
@Override | ||
public boolean contains(E e) { | ||
return linkedList.contains(e); | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return linkedList.getSize(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return linkedList.isEmpty(); | ||
} | ||
} |