越而胜己 / Beyond awesome

Another Processing project - Visual Bubble Sort! This project is based on Jack's project Visual Selective Sort. I changed the algorithm part of his project and made a port of bubble sorting.

Preview here: Click Me. Fork here: Click Me. Jack is the one who deserves the most credits. Thank him a lot!

Here is some code for sorting integers:

int i = 0, j = 0, temp = 0;
int[] a = new int[]{2,5,64,5,23,52,27,99,14,65};
void setup(){
  background(255);
  int x;
  size(500,300);
  fill(255,0,0);
  for (x = 0; x < 10; x++){
    rect(20+x*20, 20, 18, a[x]*2);
  }
  bubble();
  fill(0,255,0);
  for (x = 0; x < 10; x++){
    rect(250+x*20, 20, 18, a[x]*2);
  }
}

void select(){
  for (i = 0; i < 10; i++){
    for (j = i + 1; j < 10; j++){
      if (a[i] > a[j]){
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
      }
    }
  }
  for (i = 0; i < 10; i++){
    print (a[i] + " ");
  }
}

void bubble(){
  for (i = 0; i < 10; i++){
    for (j = 0; j < 9 - i; j++){
      if (a[j] > a[j+1]){
        temp = a[j+1];
        a[j+1] = a[j];
        a[j] = temp;
      }
    }
  }
  for (i = 0; i < 10; i++){
    print (a[i] + " ");
  }
}