Javascript コードで「FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory」というエラーが表示されます。このコードを実行するにはどうすればよいですか? Python とまったく同じことを行っていて、Python でも動作するため、コードに欠陥は見られませんが、Javascript ではメモリ エラーが発生します。以下は私のコードです。
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);
基本的に、ソート アルゴリズムを実装しようとしています。ご協力をお願いします。