1
I found this script that colors every time I click on a row, column in particular, but I wanted to color a column, row during a certain condition.
my idea was to make the same example: http://www.exforsys.com/tutorials/c-algorithms/comb-sort.html where it is in bold
The condition would be to color every time there is a value exchange in the array (trocaValores(arrayNumeros[i], arrayNumeros[i+gap]);)
Let’s say I have this sequence of numbers.
[3][6][1][7]
for example: when making the exchange, print colorful [3] and [6] in the table created.
I mean, it would look like this when I printed the table: [1][6][3][7]
If you look here, you can understand better:
http://scarsphoto.com.br/combsort/combsort.html
function trocaValores(a, b){
tempValor = a.valor;
a.setValor(b.valor);
b.setValor(tempValor);
}
$('td').click(function() {
$(this).css('backgroundColor', '#000');
});
here I create a dynamic table to go "printing" the array during execution (every time there is the exchange of values, it prints this table)
function adicionaTabela() {
contador++;
var myTableDiv = document.getElementById("tabelaDinamica");
var table = document.createElement('TABLE');
table.border='1';
var tableBody = document.createElement('TBODY');
table.appendChild(tableBody);
var tr = document.createElement('TR');
tableBody.appendChild(tr);
var teste = arrayNumeros.length;
for (var j=0; j<teste; j++){
var td = document.createElement('TD');
td.width='75';
td.appendChild(document.createTextNode(arrayNumeros[j].valor));
tr.appendChild(td);
}
myTableDiv.appendChild(table);
}
there is some way to implement this?
Can you explain better what you mean by exchange of values? Where is the function
trocaValores()
?– Sergio
http://scarsphoto.com.br/combsort/combsort.js here is the script, but I updated the topic with the function.
– Jose Maximilian
@Josemaximilian. How and where you call Function
trocaValores
?– Fernando Leal
in the example link is written in C, however, they are random combinations. Their combinations are Static or Random?
– Daniel Omine