Home > IB Computer Science 2014 > Bubblesort Java class

Bubblesort Java class

You can copy and paste this into Netbeans to practice coding Bubblesort. All that is required is the implementation of the sort() method.

 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bubblesort;

/**
 *
 * @author kobzaje
 */
public class BubbleSortMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        BubbleSort bs = new BubbleSort();
        bs.sort();
        bs.print();
    }
}

class BubbleSort {

    int[] array = {7, 3, 8, 2, 1, 6, 4, 5};

    void sort() {
        // DO THIS BIT
    }

    void print() {
        for(int i = 0; i<array.length; i++){
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s