Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

mansikagrawal
Copy link
Contributor

@mansikagrawal mansikagrawal commented Mar 6, 2020

Fixes # 1664

Checklist:

  • [ Done] 4 space indentation.
  • [Done ] Coding conventions are followed.
  • [Done ] Input is taken dynamically.
  • [Done ] Sample Input / Output is added at the end of file.
  • [Done ] Logic Documentation (Comments).
  • [Done ] File names are correct.

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

We're happy to help you get this ready -- don't be afraid to ask for help.

Thanks!

@asha15
Copy link
Collaborator

asha15 commented Mar 7, 2020

Specify the issue number next to Fixes #

@mansikagrawal
Copy link
Contributor Author

@asha15 Please check I had updated the comment

@somya-kapoor
Copy link
Collaborator

somya-kapoor commented Mar 8, 2020

Please change the description [x] instead of [done].
Also, change the file name to Count_Inversion.cpp

// 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;
Copy link
Collaborator

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)
Copy link
Collaborator

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 ) )
Copy link
Collaborator

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);
Copy link
Collaborator

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 )
Copy link
Collaborator

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++ )
Copy link
Collaborator

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;
Copy link
Collaborator

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++ )
Copy link
Collaborator

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 mansikagrawal mentioned this pull request Mar 8, 2020
6 tasks
@somya-kapoor
Copy link
Collaborator

@mansikagrawal If you are creating a new PR for the same issue, please close the other existing PR.

@mansikagrawal mansikagrawal mentioned this pull request Mar 25, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants