aalhour / C-Sharp-Algorithms

:books: :chart_with_upwards_trend: Plug-and-play class-library project of standard Data Structures and Algorithms in C#
MIT License
5.91k stars 1.4k forks source link

A small improvement for BubbleSorter and add the unit test #135

Closed yanxiaodi closed 4 years ago

yanxiaodi commented 4 years ago

Describe the bug Just found a trivial issue of BubbleSorter:

for (int index = 0; index < collection.Count - 1; index++)

It would be better if use collection.Count - i -1 here because after each passthrough we can confirm that the value we've bubbled up to the right is in its correct position.

Also I didn't find the unit test for it.

Actually this fix doesn't change the time complexity at all so just my two cents.

I've made a PR to fix it. Thanks.

github-actions[bot] commented 4 years ago

Thanks for supporting the development of C# Algorithms with your first issue! We look forward to handling it.