mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add KthElementFinder algorithm (#5836)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.thealgorithms.datastructures.heaps;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class KthElementFinderTest {
|
||||
@Test
|
||||
public void testFindKthLargest() {
|
||||
int[] nums = {3, 2, 1, 5, 6, 4};
|
||||
assertEquals(5, KthElementFinder.findKthLargest(nums, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindKthSmallest() {
|
||||
int[] nums = {7, 10, 4, 3, 20, 15};
|
||||
assertEquals(7, KthElementFinder.findKthSmallest(nums, 3));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user