Minimal, static Java templates for classic sorting/searching on int[]: binary search + lower/upper bound, bubble/insertion/merge/heap/quick (3-way), counting, radix (LSD).
BinarySearch.java
– binary search + lower/upper bound.BubbleSort.java
– stable, adaptive bubble with last‑swap boundary.InsertionSort.java
– stable insertion; includes[lo..hi]
overload.MergeSort.java
– stable top‑down merge with early‑exit.HeapSort.java
– in‑place heap (max‑heap), not stable.QuickSort3Way.java
– Dijkstra 3‑way with median‑of‑three + smaller‑side‑first.RadixSort.java
– LSD base‑256 for full signedint
(negatives OK), plus a simple base‑10 non‑negative demo.CountingSort.java
– stable counting sort with[min..max]
and auto‑detect overload.
- Copy the class (or just the static method) into your project.
- Rename the class/methods.
- If needed, adapt comparisons (e.g., reverse order), or change ranges like
[lo..hi]
. - For objects, consider writing a comparator‑based variant in your project.
These are deliberately minimal and self‑contained so they’re quick to reuse.