Implementing bubble sort algorithm in an ArrayList
i am completely lost in generating a bubble sort algorithm for an ArrayList.
from what i read, i understand the idea behing bubble sort is comparing adjacent elements and swapping first and second if the first value is bigger. lets say my ArrayList has 5 items, how will the comparison be? compare 1 and 5 first, then 2 and 4, then 3 and ?
any help and samples will be highly appreciated.
Last edited by ant.eater; 11-30-2005 at 01:54 PM.
First round - items 0 to 4
Start with items 0 and 1; if 0 is larger than 1, swap them; move to element 1, if element 1 is larger than element 2, swap them, etc. Largest will be item 4
Second round - items 0 to 3
Third round - items 0 to 2, etc.
You can also create a "short cut" flag which stops the process if there are no swaps on a round ...
By Gengar003 in forum Java
Last Post: 05-15-2005, 06:14 AM
By D. Patrick Hoerter in forum Database
Last Post: 06-26-2000, 04:57 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL