$29
Objectives:
• Learn how to implement sorting algorithms.
Description:
The follow is the struct you need for this lab: typedef struct {
int id;
int age;
float salary;
} Employee;
Implement the following functions:
void * readFile (void)
• This function reads data from the employeeInfo.csv file, creates an array of Employee, initialize the array with their information. This returns the array of Employees.
void printEmployees (void * empArray, int size)
• Display an employee array.
void swap (void * a, void * b)
• A utility function to swap two elements
void quickSort (void * empArray, int left, int right)
• The key process in quickSort is partition ().
• This function sorts the array of Employee based on the employee's id.
int partition (void * empArray, int low, int high)
• Target of partitions is, given an array and pick a random element as pivot.
• Put its pivot at its correct position in sorted array and put all smaller elements (smaller than the pivot) before pivot and put all greater elements (greater than the pivot) after the pivot. All this should be done in linear time.
void freeArray (void * empArray)
• This function frees all dynamically-allocated memories.
Every user-defined function must have a comment describing:
• What function does;
• What parameter values are;
• What value it returns.
1
Section A
Example from the terminal window:
$ ./a.out
Given array is
Employee ID : 7; Age : 64; Salary : $97897.12
Employee ID : 12; Age : 40; Salary : $88801.60
. . .
Employee ID : 1; Age : 28; Salary : $53761.82
============================================================ Sorted array is
Employee ID : 0; Age : 44; Salary : $54691.36
Employee ID : 1; Age : 28; Salary : $53761.82
. . .
Employee ID : 14; Age : 30; Salary : $72835.89
============================================================
Grading Criteria:
• Main program: 6 points
• readFile function: 4 points
• swap function: 2 points
• quickSort function: 6 points
• partition function: 6 points
• printEmployees function: 4 points
• freeArray function: 2 points
Note:
• If your code does not compile with –Wall and –Werror, you will receive a zero for this assignment.
• You need to finish at least three peer reviews within three days of this lab. Otherwise, you will get a 20% penalty.
• You will lose points if you don’t have enough comments.
2