You should use 10 threads in your program. Your program will read in 1 million unsorted…
- User
You should use 10 threads in your program. Your program will read in 1 million unsorted numbers from numbers.dat into an array. Then you will logically split the array into 10 sections – each section will have 100,000 numbers. You will call pthread_create( ) 10 times and pass each section of the array to the thread to sort using the bubble sort algorithm. Once all the threads have returned, you will merge 2 adjacent sections into a sorted super section, and continue to do that until all the smaller sorted sections are in one large sorted section – which will be the entire array of 1 million numbers. Then print the array to a file. Then you will call sort -c to verify the output file is sorted.
- Assistant
- User
Avoid using a thread class, we only want to use pthreads
- Assistant
- User
Explain the code below: void Merge(int* iLeft, int* iRight, int iLeftSize, int iRightSize){ int lLeft = 0, lRight = 0, lMerged = 0; int* lTemp = new int[iLeftSize + iRightSize]; while(lLeft < iLeftSize && lRight < iRightSize){ lTemp[lMerged++] = iLeft[lLeft] < iRight[lRight] ? iLeft[lLeft++] : iRight[lRight++]; } while(lLeft < iLeftSize){ lTemp[lMerged++] = iLeft[lLeft++]; } while(lRight < iRightSize){ lTemp[lMerged++] = iRight[lRight++]; } memcpy(iLeft, lTemp, sizeof(int) * (iLeftSize + iRightSize)); delete[] lTemp;}
- Assistant
The code you provided implements a function called
Mergethat is used to merge two sorted arrays into a single sorted array. Here's a breakdown of what each part of the code does:-
The function takes four parameters:
iLeftandiRight, which are pointers to the start of the left and right arrays,iLeftSizeandiRightSize, which are the sizes of the left and right arrays respectively.
-