Ahí está el siguiente código. Está en javascript.
función nonRecursiveQuickSort (unSortedArray) {
var tempStack = [unSortedArray];
var sortedArray = [];
while (tempStack.length) {
var tempVar = tempStack.pop ();
var currentLength = tempVar.length;
- ¿Puedes darme una idea para un juego simple que implemente el algoritmo (como el algoritmo A *) o la inteligencia artificial para NPC en el juego?
- ¿Cuándo podemos usar la máquina de vectores de soporte básica sobre otros algoritmos de clasificación?
- ¿Cuáles son algunas de las implementaciones de cola (montón) de prioridad más rápida en C ++?
- ¿Hay alguna diferencia en la asignación de memoria entre la estructura y la matriz multidimensional?
- ¿Es posible el algoritmo de compresión que se muestra en Silicon Valley en realidad?
if (currentLength == 1) {
sortedArray.push (tempVar [0]);
continuar;
}
var pivotElement = tempVar [0];
var leftElement = [];
var rightElement = [];
for (var iter = 1; iter <currentLength; iter ++) {
if (tempVar [iter] <pivotElement) {
leftElement.push (tempVar [iter]);
} más {
rightElement.push (tempVar [iter]);
}
}
leftElement.push (pivotElement);
if (rightElement.length)
tempStack.push (rightElement);
if (leftElement.length)
tempStack.push (leftElement);
}
return sortedArray;
}