Skip to content

Commit

Permalink
Update 1649.Create-Sorted-Array-through-Instructions_DivideConque.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jun 27, 2022
1 parent fe1779d commit a5504ee
Showing 1 changed file with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,36 @@ class Solution {
numSmaller[i] += iter-(sorted+a);
}

int i=a, j=mid+1, p = 0;
while (i<=mid && j<=b)
{
if (sorted[i]<=sorted[j])
{
temp[p] = sorted[i];
i++;
}
else
{
temp[p] = sorted[j];
j++;
}
p++;
}
while (i<=mid)
{
temp[p] = sorted[i];
i++;
p++;
}
while (j<=b)
{
temp[p] = sorted[j];
j++;
p++;
}
for (int i=0; i<b-a+1; i++)
sorted[a+i] = temp[i];
inplace_merge(sorted+a, sorted+mid+1, sorted+b+1);

// int i=a, j=mid+1, p = 0;
// while (i<=mid && j<=b)
// {
// if (sorted[i]<=sorted[j])
// {
// temp[p] = sorted[i];
// i++;
// }
// else
// {
// temp[p] = sorted[j];
// j++;
// }
// p++;
// }
// while (i<=mid)
// {
// temp[p] = sorted[i];
// i++;
// p++;
// }
// while (j<=b)
// {
// temp[p] = sorted[j];
// j++;
// p++;
// }
// for (int i=0; i<b-a+1; i++)
// sorted[a+i] = temp[i];
}
};


// X X 3 X 3 Y Y Y

0 comments on commit a5504ee

Please sign in to comment.