Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PASO 1
- float A[] = new float[20];//posiciones del vector
- void setup()
- {
- fullScreen(P3D);
- for (int i =0; i<A.length-1; i++)
- {
- //PASO 2
- A[i]=random(height);//Asignacion de valores del vector
- }
- }
- void draw() {
- mostrar();
- //Metodo de Burbuja
- if (mousePressed==true) { //click para ordenar
- for (int i = 0; i<A.length-1; i++) {
- for (int j = 0; j<A.length-1; j++) {
- //PASO 3
- if (A[j+1]>A[j]) { // > mayor-menor; < menor-mayor
- float aux=A[j+1];
- A[j+1]=A[j];
- A[j]=aux;
- }
- }
- }
- }
- }
- //PASO 4
- void mostrar() {
- background(255);
- for (int i = 0; i<A.length; i++) {
- pushMatrix();
- stroke(0);
- translate(map(i, 0, A.length, width/A.length, width), height/2);
- noFill();
- box(A[i]);
- popMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement