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

merge_sort.cpp: Add cpp merge sort. #492

Merged
merged 1 commit into from
Oct 31, 2018

Conversation

yashasingh
Copy link
Member

Cpp implementation of merge sort for NITSkmOS/Algorithms.

closes #258

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

By submitting this pull request I confirm I've read and complied with the
below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the commit guidelines for this project.
  • My code follows the standard code structure.
  • This pull request has a descriptive title. For example, {Tag}: Add {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
  • This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met.
  • I have mentioned the issue number correctly (with hyperlink) in this pull request description.

After you submit your pull request, DO NOT click the 'Update Branch' button.

}

void join (std::vector<int>& arr, int l, int m, int r) {
// merge operation of merge sort.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Spaces used instead of tabs.

Origin: SpaceConsistencyBear, Section: all.cpp.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpw4int4b9/merge_sort/Cpp/merge_sort.cpp
+++ b/tmp/tmpw4int4b9/merge_sort/Cpp/merge_sort.cpp
@@ -23,7 +23,7 @@
 }
 
 void join (std::vector<int>& arr, int l, int m, int r) {
-	//  merge operation of merge sort.
+	//	merge operation of merge sort.
 	int i, j, k;
 	int s1 = m-l+1, s2 = r-m;
 	int L[s1], R[s2];

return 0;
}

void join (std::vector<int>& arr, int l, int m, int r) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before ( in function call [whitespace/parens] [4]

Origin: CPPLintBear, Section: all.cpplint.

arr[k] = L[i];
i++;
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An else should appear on the same line as the preceding } [whitespace/newline] [4]

Origin: CPPLintBear, Section: all.cpplint.

arr[k] = L[i];
i++;
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an else has a brace on one side, it should have it on both [readability/braces] [5]

Origin: CPPLintBear, Section: all.cpplint.

}
}

void sort (std::vector<int>& arr, int l, int r) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before ( in function call [whitespace/parens] [4]

Origin: CPPLintBear, Section: all.cpplint.

}
}

void show (std::vector<int>& arr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before ( in function call [whitespace/parens] [4]

Origin: CPPLintBear, Section: all.cpplint.

@yashasingh
Copy link
Member Author

@sangamcse Please Review. 🙂

README.md Outdated
@@ -15,7 +15,7 @@ This repository contains examples of various algorithms written on different pro
| Algorithm | C | CPP | Java | Python |
|:----------------------------------------------------------------------------------------------- |:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|
| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [:octocat:](euclidean_gcd/C) | | [:octocat:](euclidean_gcd/Java) | [:octocat:](euclidean_gcd/Python) |
| [Merge Sort](https://en.wikipedia.org/wiki/Merge_sort) | [:octocat:](merge_sort/C) | | [:octocat:](merge_sort/Java) | [:octocat:](merge_sort/Python) |
| [Merge Sort](https://en.wikipedia.org/wiki/Merge_sort) | [:octocat:](merge_sort/C) | [:octocat:](merge_sort/Cpp) | [:octocat:](merge_sort/Java) | [:octocat:](merge_sort/Python) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have used tabs.

int main() {
int n = 10, a, i, arr[] = {2, 4, 3, 6, 5, 1, 9, 0, 8, 7};
// scanf("%d", &n); //For custom input
// printf("Enter %ld number (space separated): ", n); //For custom inup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove scanf and printf from cpp code.

Cpp implementation of merge sort for NITSkmOS/Algorithms

closes NITSkmOS#258
@yashasingh
Copy link
Member Author

@sangamcse Please review 🙂

@sangamcse
Copy link
Member

ack 61daeaf

@sangamcse
Copy link
Member

@sangamcse ff

@sangamcse
Copy link
Member

Hey! I'm GitMate.io! This pull request is being fastforwarded automatically. Please DO NOT push while fastforward is in progress or your changes would be lost permanently ⚠️

@sangamcse sangamcse merged commit 61daeaf into NITSkmOS:master Oct 31, 2018
@sangamcse
Copy link
Member

Automated fastforward with GitMate.io was successful! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Algo] Merge Sort [C++]
2 participants