MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / rearrange

Method rearrange

RearrangeArrayAlternatively.java:6–32  ·  view source on GitHub ↗
(int arr[], int n)

Source from the content-addressed store, hash-verified

4 // n: size of array
5 //Function to rearrange the array elements alternately.
6 public static void rearrange(int arr[], int n){
7
8 // Your code here
9 int j=0,k=n-1;
10 int key=arr[n-1]+1;
11 for(int i=0;i<n;i++)
12 {
13 // even should be max
14 if(i%2==0)
15 {
16 arr[i]=((arr[k]%key)*key)+arr[i];
17 k--;
18 }
19 // odd should be min
20 else
21 {
22 arr[i] = ((arr[j]%key)*key)+arr[i];
23 j++;
24 }
25 }
26
27 for(int i=0;i<n;i++)
28 {
29 arr[i]/=key;
30 }
31
32 }
33
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected