Question
JAVA Help: RULES: You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may
JAVA Help:
RULES:
- You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may be used, whereas something like ArrayList must be explicitly imported so it is disallowed.
- You may not use any built-in functionality for copying an array, like System.arrayCopy(), Arrays.copyOf(), Object.clone(), Arrays.stream, etc. If you want to copy an array, you should do it manually (i.e. create a new array and transfer the data).
1st Problem-
Create the following method that, given an array of integers and a cardinal number, k, finds the kth smallest number in the array. You are not allowed to call any sorting functionality. Remember, a cardinal number starts with one; for the smallest value, k=1. Assume, there are enough items in the array to find the kth value.
public static int smallest(int[] arr, int k)
Examples:
smallest({1,1,1,3,3,4,5,5,5}, 5) --> 3
2nd Problem-
Create the following method that, given an array, it pushes all evens to the beginning and all odds to the end of the array; order between evens is preserved, and order between odds is preserved. So, modification happens in-place and the return type is void.
public static void partition(int[] arr)
Examples:
partition({10,9,8,7,6,5,4}) --> {10, 8, 6, 4, 9, 7, 5} partition({4,7,6,2,10,9,101,3}) --> {4, 6, 2, 10, 7, 9, 101, 3}
Please help with these 2 problems. Comments in code will be very appreciated. Thank You! :)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started