I have an assignment and i need working code. Before i start i want to understand the problem but i cant figure out how to write it.
I have an array of data, take this for example
var arr = new byte[] {5,3,1,7,8,5,3,2,6,7,9,3,2,4,2,1} I need to split this array in half, throw it into a thread pool and do that recursively until i have <=2 elements. If i have 2 elements i need to check which is less and put it on the left side then return the array.
What i don't understand is how do i merge the array? am i suppose to split the array, throw a thread into the pool and block until its ready? How do i get the results of the thread? I'm going to assume its not possible to merge the arrays without blocking?
Heres what i have so far.
static void Main(string[] args) { var arr = new byte[] { 5, 3, 1, 7, 8, 5, 3, 2, 6, 7, 9, 3, 2, 4, 2, 1 }; var newarr = Sort(arr); Console.Write(BitConverter.ToString(newarr)); } static byte[] Sort(byte[] arr) { if (arr.Length <= 2) return arr; if (arr.Length == 2) { if (arr[0] > arr[1]) { var t = arr[0]; arr[0] = arr[1]; arr[1] = t; } return arr; } var arr1 = arr.Take(arr.Length / 2).ToArray(); var arr2 = arr.Skip(arr1.Count()).ToArray(); //?? return arr; } Note: The prof did say we can ask others for help. I think i can solve this without asking but i want to get the best answer. Threading is my weakness (i dont everything else, db, binary io, web interface, just never complex threads)