I am trying to create a recursive function, say Merge Sort. I want to create a new process every time I call the function.
Basically I want to divide the task into two parts every time I call the function and pass each part to a new process.
Here is my code:
merge.js
rocess.stdin.resume();
process.stdin.setEncoding(‘utf8’);
process.stdin.on(‘data’, function (chunk) {
var arr = chunk.trim().split(’ ');
mergeSort(arr,0,arr.length - 1);
// I want to create new threads like this
// CreateNewLeftThread
// CreateNewRightThread
// Join(lefThread.rightThread)
function mergeSort(arr,left,right) {
if (left < right) {
var mid = Math.floor(left + (right - left)/2);
mergeSort(arr,left,mid);
mergeSort(arr,mid+1,right);
merge(arr,left,right,mid);
}
}
function Merge(Parameters) {
/*Code Here*/
}
process.exit(0);
});