Created
May 13, 2018 18:06
-
-
Save ntakouris/35d5603e2dc4d80b0d6ca3944528822a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class PedestalledLeanLinkedList<T extends ContradictableType> { | |
LinkedList<T> types = new LinkedList<>(); | |
public void insert(T type) { | |
boolean first = true; | |
for (Iterator<T> iterator = types.iterator(); iterator.hasNext(); ) { | |
ContradictableType current = iterator.next(); | |
if (first) { | |
first = false; | |
continue; | |
} | |
if (current.equivalentTo(type)) { | |
return; | |
} | |
if (current.cancelsOutWith(type)) { | |
iterator.remove(); | |
return; | |
} | |
} | |
types.add(type); | |
} | |
public T poll() { | |
return types.pollFirst(); | |
} | |
public T peek() { | |
return types.peekFirst(); | |
} | |
public boolean isEmpty() { | |
return peek() == null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment