Javascript 코드에서 "치명적인 오류 : CALL_AND_RETRY_0 할당 실패 - 메모리 부족 프로세스"오류가 발생합니다. 어떻게하면이 코드를 실행할 수 있습니까? 파이썬에서와 똑같은 일을하고 파이썬에서 작동하기 때문에 코드에 결함이 없습니다.하지만 자바 스크립트에서는 메모리 오류가 발생합니다. 아래는 제 코드입니다. 자바 스크립트 정렬. 할당 오류 프로세스 메모리 부족 오류
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;
for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;
return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.log("Sorted Array:", sample_arr);
기본적으로 내가 정렬 알고리즘, 내가 크게 도움을 주셔서 감사합니다 것 을 구현하기 위해 노력하고 있습니다.
이 종류로 달성하려는 것은 무엇입니까? – PHPglue
정렬 된 버전을 얻기 위해 뒤죽박죽 된 배열을 정렬하려고합니다. –