4 Replies - 505 Views - Last Post: 03 April 2013 - 11:22 AM Rate Topic: -----

#1 aripal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-April 13

I have problems sorting my array by using bubblesort?

Posted 03 April 2013 - 10:36 AM


public class BubbleSort {

    public void Bubble(int list[]) {
        for (int i = 1; i < list.length; i++) {
            for (int j = 0; j < list.length - i; j++) {

                if (list[j] < list[j + i]) {
                    int change = list[j];
                    list[j] = list[j + 1];
                    list[j + 1] = change;

                } // end if setting.
            } // end inside loop
        } // end outside loop

        for (int i = 0; i < list.length; i++) {
            System.out.print(list[i] + " ");
        } // loop

    } // end BubbleSort method
}// end class BubbleSort




Is This A Good Question/Topic? 0
  • +

Replies To: I have problems sorting my array by using bubblesort?

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: I have problems sorting my array by using bubblesort?

Posted 03 April 2013 - 10:40 AM

Loops are wrong: http://www.dreaminco.../snippet513.htm
Was This Post Helpful? 0
  • +
  • -

#3 aripal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-April 13

Re: I have problems sorting my array by using bubblesort?

Posted 03 April 2013 - 11:13 AM

The link is not working. Is there something I have missed?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: I have problems sorting my array by using bubblesort?

Posted 03 April 2013 - 11:18 AM

You're right. Try instead http://en.wikipedia....iki/Bubble_sort
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7744
  • View blog
  • Posts: 13,083
  • Joined: 19-March 11

Re: I have problems sorting my array by using bubblesort?

Posted 03 April 2013 - 11:22 AM

Snippets are broken.

Just for practice, can we ask you to be more specific about what problems you're having? Imagine that you're talking to busy people at their desks who can take a few minutes to answer a question. The less time we spend figuring out what your problem is, the more time we can devote to helping you solve it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1