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

Added Quick Select [C] #53

Merged
merged 1 commit into from
Mar 16, 2017
Merged

Added Quick Select [C] #53

merged 1 commit into from
Mar 16, 2017

Conversation

yashLadha
Copy link
Member

@yashLadha yashLadha commented Mar 15, 2017

Fixes #10

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

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the coding guidelines for this project.
  • My code follows the skeleton code structure.
  • This pull request has a descriptive title. For example, Added {Algorithm name} [{Language}], not Update README.md or Added new code.

@singhpratyush
Copy link
Member

@yashLadha: Please mention an issue that is completely closed by this PR.

@singhpratyush
Copy link
Member

Also it is clear that you have made a false tick on the requirements mentioned for the PR. Please correct the errors.

@yashLadha yashLadha changed the title Quick select Algo Quick select Algo : FIxes #10 Mar 15, 2017
@singhpratyush
Copy link
Member

@yashLadha : This PR is not consistent with contributing guidelines. Please refer to it and make the changes.

@yashLadha
Copy link
Member Author

The closing issue link is mentioned in my commit message.

@yashLadha yashLadha changed the title Quick select Algo : FIxes #10 Added Quick Select [C] Mar 15, 2017
} else {
return quick_select(ar, pivot_index + 1, right, pos);
}
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Though this case will never be reached, it looks confusing to return 0 when we have to return one of the numbers from the array. What do you think @yashLadha?

Copy link
Member Author

@yashLadha yashLadha Mar 15, 2017

Choose a reason for hiding this comment

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

Sir it is because of a warning that all the return statements are inside the conditional blocks and there is a warning issued at this point because function will not return any value if in any hypothetical case it doesn't go into any conditional block statement, and it requires a return statement. If you wan't i can remove it?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that there would be a warning.

}

int quick_select(int *ar, int left, int right, int pos) {
int pivot_index = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Assigned value to variable pivot_index has not been used.

int ar[] = {10, 5, 1, 6, 7, 3, 2, 4, 8, 9};
printf("%d\n", quick_select(ar, 0, 9, 3));
return 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

End with a new line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added newline

@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
Copy link
Member

Choose a reason for hiding this comment

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

Module never used.

@yashLadha yashLadha force-pushed the select_algo branch 4 times, most recently from 3bbc5ce to b1fb210 Compare March 15, 2017 15:30
@yashLadha
Copy link
Member Author

Ammended Necessary changes.

@singhpratyush
Copy link
Member

Looks okay. Let's wait for some more eyes.

@@ -0,0 +1,45 @@
#include <stdio.h>

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add comments about the parameters making it easy for a reader to know about the work of the parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

added the comments. Can review them.

* right : right index of the subarray
* pos : position to find the element using quick sort
* pivot_index : pivot index
* return : int
Copy link
Member

Choose a reason for hiding this comment

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

Better be specific about what int.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the return type of function

Copy link
Member

Choose a reason for hiding this comment

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

But it looks strange. We have a list of parameters and out of nowhere we see the return type. What I see is that the return type is already indicated very clearly in C (int quick_select(...) {}). It would be better to add what it returns instead of return type.

Copy link
Member Author

Choose a reason for hiding this comment

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

the logical meaning or the variable name.

Copy link
Member

Choose a reason for hiding this comment

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

The logical meaning.

@singhpratyush
Copy link
Member

@Monal5031 : Do things look good?

Copy link
Member

@Monal5031 Monal5031 left a comment

Choose a reason for hiding this comment

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

Yeah, everything look's fine.

@singhpratyush singhpratyush merged commit 4733102 into master Mar 16, 2017
@singhpratyush singhpratyush deleted the select_algo branch March 16, 2017 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants