Informática
Informática
Informática
array[firstIndex] = array[secondIndex];
array[secondIndex] = temp;
};
swap(testArray, 0, 1);
println(testArray);
//Probando el algoritmo
swap(testArray, 0, 2);
swap(testArray, 1, 2);
minIndex = i;
minValue = array[i];
return minIndex;
};
println("The index of the minimum value of the subarray starting at index 2 is " + index + "." );
Program.assertEqual(index, 4);
//Probando el algoritmo
Program.assertEqual(indexOfMinimum(array,7),7);
Program.assertEqual(indexOfMinimum(array,5),6);
Desafío: implementa el ordenamiento por selección
var swap = function(array, firstIndex, secondIndex) {
array[firstIndex] = array[secondIndex];
array[secondIndex] = temp;
};
minIndex = i;
minValue = array[i];
return minIndex;
};
var i;
var a;
for(i=0;i<array.length ;i++) {
a = indexOfMinimum(array,i);
swap(array,i,a);
};
selectionSort(array);
//Segunda parte
selectionSort(array1);
Program.assertEqual(array1,[6,7,15,22,30,88,99]);
Desafío: implementa el intercambio
var swap = function(array, firstIndex, secondIndex) {
array[firstIndex] = array[secondIndex];
array[secondIndex] = temp;
};
swap(testArray, 0, 1);
println(testArray);
//Probando el algoritmo
swap(testArray, 0, 2);
swap(testArray, 1, 2);
minIndex = i;
minValue = array[i];
return minIndex;
};
println("The index of the minimum value of the subarray starting at index 2 is " + index + "." );
Program.assertEqual(index, 4);
//Probando el algoritmo
Program.assertEqual(indexOfMinimum(array,7),7);
Program.assertEqual(indexOfMinimum(array,5),6);
Desafío: implementa el ordenamiento por selección
var swap = function(array, firstIndex, secondIndex) {
array[firstIndex] = array[secondIndex];
array[secondIndex] = temp;
};
minIndex = i;
minValue = array[i];
return minIndex;
};
var i;
var a;
for(i=0;i<array.length ;i++) {
a = indexOfMinimum(array,i);
swap(array,i,a);
};
selectionSort(array);
//Segunda parte
selectionSort(array1);
Program.assertEqual(array1,[6,7,15,22,30,88,99]);
Desafío: búsqueda binaria
/* Returns either the index of the location in the array,
var min = 0;
var guess;
var intentos = 0;
while (max>=min){
intentos++;
//promediando
guess = Math.floor((max+min)/2);
if(array[guess]===targetValue){
return guess;
else if(array[guess]<targetValue){
min=guess+1;
}
else{
max=guess-1;
return -1;
};
var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
//Probando el programa