Input


Code
function bubbleSort(items){
    var len = items.length,i, j, stop;
    for (i=0; i < len; i++){
        for (j=0, stop=len-i; j < stop; j++){
            if (items[j] > items[j+1]){
                swap(items, j, j+1);
            }
        }
    }

    return items;
}

                
function move(n, from, to, via) {
  if (n > 0) {
    move(n-1, from, via, to)
    print("Move disk from " + from + " to " + to)
    move(n-1, via, to, from)
  }
}
var  b = [8];//number of queens
 
function mainChess() {
    var y = 0;
    b[0] = -1;
    while (y >= 0) {
        do {
            b[y]++;
        } while ((b[y] < 8) && unsafe(y));
        if (b[y] < 8) {
            if (y < 7) {
                b[++y] = -1;
            } else {
                break; //solution found
            }
        } 
    else {
            y--;
        }
    }
}

function unsafe( y) {
    var x = b[y];
    for (var i = 1; i <= y; i++) {
      var t = b[y - i];
      if (t == x || t == x - i || t == x + i) {
        return true;
        }
    }
    return false;
}
​
function selectionSort(items){
    var len = items.length, min;
    
    for (i=0; i < len; i++){
        min = i;
    
        for (j=i+1; j < len; j++){
            if (items[j] < items[min]){
                min = j;
            }
        }
    
        if (i != min){
            swap(items, i, min);
        }
    }
}

function swap(firstIndex, secondIndex) {
var temp = UserList[firstIndex];
UserList[firstIndex] = UserList[secondIndex];
UserList[secondIndex] = temp;
}
Animation
Blog Comments Report Bug Poll Creative Commons License