Implementing bubble sort algorithm in an ArrayList

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Implementing bubble sort algorithm in an ArrayList

  1. #1
    Join Date
    Nov 2005

    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.

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

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center