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

Add Cocktail Sort #660

Merged
merged 9 commits into from
Oct 7, 2023
Merged

Add Cocktail Sort #660

merged 9 commits into from
Oct 7, 2023

Conversation

migueldalberto
Copy link
Contributor

The cocktail sort (also known as cocktail shaker sort, bidirectional bubble sort, shaker sort, ripple sort, shuffle sort, or shuttle sort) is a variant of the bubble sort algorithm. It extends the bubble sort by operating in both directions (from array's beginning to its end, and from array's end to its beginning).

I based the implementation on the Wikipedia page about Cocktail Sort.

Also added this sort on the sort_tests.go

Copy link
Member

@raklaptudirm raklaptudirm left a comment

Choose a reason for hiding this comment

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

Add some inline comments explaining the algorithm as far as possible.

Copy link
Member

@raklaptudirm raklaptudirm left a comment

Choose a reason for hiding this comment

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

I would suggest adding start and end variables to make the sort more efficient.

sort/cocktailsort.go Outdated Show resolved Hide resolved
sort/cocktailsort.go Outdated Show resolved Hide resolved
raklaptudirm
raklaptudirm previously approved these changes Oct 5, 2023
sort/cocktailsort.go Outdated Show resolved Hide resolved
@raklaptudirm raklaptudirm merged commit 02fde76 into TheAlgorithms:master Oct 7, 2023
3 checks passed
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