DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Implementing bubble sort algorithm in an ArrayList

    hi,

    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.


    thanks.
    Last edited by ant.eater; 11-30-2005 at 01:54 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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 ...

Similar Threads

  1. Replies: 10
    Last Post: 05-15-2005, 06:14 AM
  2. Re: Sort problem in MS SQL Server 7.0
    By D. Patrick Hoerter in forum Database
    Replies: 1
    Last Post: 06-26-2000, 04:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links