C代写:CS240 Pointer to Functions

练习函数指针的使用方法的lab作业,跑过测试即可。

Before the Lab

Study in the slides the material related to pointer to functions..

Step 1. Setting up Your Environment

Copy your lab files and enter the appropriate directories.

$ cd$ cd cs240$ tar -xvf /homes/cs240/lab8-ptr-to-funcs/lab8-src.tar$ cd lab8-src

Step 2. Pointer to functions Write a Sorting Function to Sort any Type of Array

Open the file mysort.c . In there you will implement the function

1
2
3
4
5
void mysort( int n,           // Number of elements
int elementSize, // Size of each element
void * array, // Pointer to an array
int ascending, // 0 -> descending; 1 -> ascending
CompareFunction compFunc ) // Comparison function.

This function takes an array of any type, the number n of elements, the elementSize, a comparison function compFunc and a flag ascending and it will sort the array passed using bubble sort or any sorting algorithm of your choice. You will also find there information of what this function should do.

To test your implementation type make and run test_mysort test1 to test_mysort test5 or type testall. IMPORTANT: You will need to modify test_mysort.c to fix compareStudentByGrade() needed for test3.

Step 3. Turning In your Project

Follow these instructions to turn in lab8:
Login to and type

cd cs240turnin -c cs240 -v -p lab8 lab8-src
]]>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注