-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Count_inversion.cpp #2242
Count_inversion.cpp #2242
Conversation
Specify the issue number next to |
@asha15 Please check I had updated the comment |
Please change the description [x] instead of [done]. |
// CPP program to count inversion sort in an array | ||
// inversion count is in an array such that arr[i] > arr[j] where i < j | ||
#include<iostream> | ||
using namespace std; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a line.
// inversion count is in an array such that arr[i] > arr[j] where i < j | ||
#include<iostream> | ||
using namespace std; | ||
int mergefn(int arr[] ,int temp[], int left, int mid, int right) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space before the comma, not after.
int j = mid; | ||
int k = left; | ||
int inv_cnt = 0; | ||
while( ( i <= mid-1 ) && ( j <= right ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the space between (( and add a space around -.
so all the remaining elements in left-subarray | ||
(arr[i+1], arr[i+2] … arr[mid]) will be greater than arr[j] */ | ||
temp[k++] = arr[j++]; | ||
inv_cnt += (mid-i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space around -.
temp[k++] = arr[i++]; | ||
/* Copy the remaining elements of right subarray | ||
(if there are any) to temp*/ | ||
while( j <= right ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space after (
while( j <= right ) | ||
temp[k++] = arr[j++]; | ||
/*Copy back the merged elements to original array*/ | ||
for( i = left ; i <= right ; i++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space after (.
Add space after comma, not before comma
{ | ||
// test cases t | ||
int t; | ||
cin>>t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space around >> and <<
cin>>n; | ||
// input array arr[] | ||
int arr[n]; | ||
for( int i=0 ; i<n ; i++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space around the operator.
@mansikagrawal If you are creating a new PR for the same issue, please close the other existing PR. |
Fixes # 1664
Checklist:
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
Changes proposed in this pull request: Added file Count_inversion.cpp
Languages Used:CPP
Files Added: Count_inversion.cpp
Thanks!