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

Method rearrange

RearrangeArrayInAlternatingPositions.java:28–58  ·  view source on GitHub ↗
(int nums[], int n)

Source from the content-addressed store, hash-verified

26 nums[start]=temp;
27 }
28 public static int[] rearrange(int nums[], int n)
29 {
30 int i=0,j=0,k=0;
31 while(k<n && i<n && j<n)
32 {
33 if(k%2==0)
34 {
35 if(nums[k]>=0)
36 {
37 i=k;
38 j=k;
39 while(i<n && nums[i]>=0) i++;
40 if(i>=n) break;
41 else rotate(nums,j,i);
42 }
43 }
44 else
45 {
46 if(nums[k]<0)
47 {
48 i=k;
49 j=k;
50 while(j<n && nums[j]<0) j++;
51 if(j>=n) break;
52 else rotate(nums,i,j);
53 }
54 }
55 k++;
56 }
57 return nums;
58 }
59}

Callers 1

mainMethod · 0.95

Calls 1

rotateMethod · 0.95

Tested by

no test coverage detected