Skip to content

remove typeof from choose_pivot(...) #5

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

Merged
merged 1 commit into from
Jun 24, 2013
Merged

remove typeof from choose_pivot(...) #5

merged 1 commit into from
Jun 24, 2013

Conversation

blackball
Copy link
Contributor

It's not making any sense to use typeof(i) to define length, since 'i' is obviously a 'int'. And it's probably not a good idea to put the choose pivot function in a separate file, this will force user to call srand() unnaturally.

It's not making any sense to use typeof(i) to define length, since 'i' is obviously a 'int'. And it's probably not a good idea to put the choose pivot function in a separate file, this will force user to call srand() unnaturally.
xtaci added a commit that referenced this pull request Jun 24, 2013
remove typeof from choose_pivot(...)
thx...
@xtaci xtaci merged commit e808f19 into xtaci:master Jun 24, 2013
@xtaci
Copy link
Owner

xtaci commented Jun 24, 2013

./include/quick_sort.h: int pivot_idx = choose_pivot(begin,end);
./include/random_select.h: int pivot_idx = choose_pivot(begin,end);

it seems putting the choose_pivot function in both quick_sort & random_select is a good idea?

@xtaci
Copy link
Owner

xtaci commented Jun 24, 2013

#define RANDOM_INIT() srand(time(NULL))
#define RANDOM_NEXT(L, R) rand() % ((R) - (L)) // gen a random integer in [L, R]

macro is good for algorithms demo, and can easily be tuned in production environment.

thanks for the advice, you can PULL REQUEST, and i will merge it.

@xtaci
Copy link
Owner

xtaci commented Jun 27, 2013

updated quick_sort & random_select using your method! thanks!

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.

2 participants