Mozilla-Campus-Club-Cummins / CompetitiveProgramming-HacktoberFest23

1 stars 25 forks source link

Issue#57 #92

Closed RutvikaWagh closed 8 months ago

RutvikaWagh commented 8 months ago

Problem Statement: Given an array A of positive integers, sort the array in ascending order such that element at index K in unsorted array stays unmoved and all other elements are sorted.

Author:[Rutvika Wagh]

Keypoint: Import of Arrays Class from java.util package that is:
    import java.util.Arrays;

Solution : ****Java Function Code:****

static int sortExceptK(int arr[], int k, int n) { // Move k-th element to end of array. int temp = arr[k]; arr[k] = arr[n-1]; arr[n-1] = temp; // Sort all elements except last one. Arrays.sort(arr, 0, n-1); // From import java.util.Arrays; // Store last element (originally k-th) int last = arr[n-1]; // Move all elements from k-th to one // position ahead. for (int i = n-1; i > k; i--){ arr[i] = arr[i-1];} } // Restore k-th element arr[k] = last; return 0; }

RutvikaWagh commented 8 months ago

This is solution to issue #92

Chaitralikore commented 8 months ago

Hi! @RutvikaWagh check the code there are some errors.

RutvikaWagh commented 8 months ago

@Chaitralikore Can you please check now