Last active
August 29, 2015 14:17
-
-
Save juliensimon/cc31d9707e7ae8e22624 to your computer and use it in GitHub Desktop.
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
// This is equivalent to: linearSearch(list, t, build(modeMoveFirst)) | |
public static <T> boolean linearSearchMoveFirst(List<T> list, T t) { | |
return linearSearch(list, t, | |
((List<T> l, int index) | |
-> { T elem = l.remove(index); l.add(0, elem); } )); | |
} | |
// This is equivalent to: linearSearch(list, t, build(modeMoveLast)) | |
public static <T> boolean linearSearchMoveLast(List<T> list, T t) { | |
return linearSearch(list, t, | |
((List<T> l, int index) | |
-> { T elem = l.remove(index); l.add(elem); } )); | |
} | |
// This is equivalent to: linearSearch(list, t, build(modeMoveUp)) | |
public static <T> boolean linearSearchMoveUp(List<T> list, T t) { | |
return linearSearch(list, t, | |
((List<T> l, int index) -> { | |
if (index != 0) { | |
Collections.swap(list, index-1, index); | |
} | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment