{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework6 - to sort Then the program should create an array...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 490/590 HOMEWORK 6 SPRING 08 PROFESSOR GODFREY MUGANDA 1. Multi-threaded Quicksort Write a program that uses threads to sort an array using the Quicksort algorithm. Recall that the Quicksort algorithm, when given a portion a [ l . . . , u ] of an array to be sorted, partitions the array into three parts: (1) a part with just one element X at position p , this is called the pivot element. That is, a [ p ] = X , (2) a part a [ l . . . p - 1] of elements all of which are less than a [ p ], (3) a part a [ p + 1 . . . u ] of elements all of which are greater or equal to a [ p ]. The algorithm then recursively sorts a [ l . . . p - 1] and a [ p + 1 . . . u ]. Implement this strategy by creating a thread to sort each portion of the array. In general, each such thread will create two other threads. The main program should take an integer on the command line: the size of an array
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: to sort. Then, the program should create an array of integes that size, populate it with random numbers, and print out the array. The program then calls a function sort(int a[ ], int size) to sort the array, this function should take an array of integers and the size of an array as parameters. Once the array is sorted, the main program should print the sorted array. The function sort(int a[ ], int size) should create the first Quicksort thread. Think carefully about the following issues, and then make the best decision in your program: (1) Does the sort function have to join the first Quicksort thread that is cre-ated? (2) Does each Quicksort thread have to join neither, one, or both of the Quick-sort threads that it creates? 1...
View Full Document

{[ snackBarMessage ]}