JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
bubble sort's loop index boundary | Reply
I don't want to be picky, but I think the sample code in the tutorial should be more precise. For bubble sort, the upper bound of the loop index should be something like this:

for (int i = 0; i < data.Length - 1; i++)
for (int j = 0; j < data.Length - 1 - i; j++)
...

Though it's obvious to experienced coders like the tutorial's author, the educational material is kind of for the beginners.
Re: bubble sort's loop index boundary (response to post by silversmith) | Reply
I don't see why the code in the tutorial wouldn't work. Could you give an example of an array where it doesn't?
Re: bubble sort's loop index boundary (response to post by dskloet) | Reply
Both will work though what silversmith suggests is more efficient. But I think the way it is in the tutorial would be easier for beginners to understand, and who would use bubblesort if they care about efficiency anyway?
Re: bubble sort's loop index boundary (response to post by dskloet) | Reply
I don't mean the tutorial's bubble sort doesn't work, though it's insertion sort indeed doesn't work.
Re: bubble sort's loop index boundary (response to post by silversmith) | Reply
This is an good article.Why you said that this article has no run porgram?
RSS