在 Data stucture and Algorithm 的 git 项目学到的:
这如果是0
,就是真注释,代码不运行,如果是1
,代码运行
#if 0
#endif
如:
#if 1
int IsLess(int a, int b) {
return a < b;
}
int IsLarger(int a, int b) {
return a > b;
}
// Define a function pointer type, which points to a function
typedef int (*ComparatorFuncPtr)(int, int);
void BubbleSort2(int *ptr, int n, ComparatorFuncPtr compare) {
for (int iMax = n - 2; iMax >= 0; iMax--) {
for (int i = 0; ____Q1_____; _____Q2____) {
if (_____Q3_____) {
____Q4____;
}
}
}
}
int TestBubbleSort2(void) {
int arr[] = {30, 50, 20, 10, 60, 40};
int len = sizeof(arr) / sizeof(arr[0]);
// a function pointer variable which points to the function IsLarger()
ComparatorFuncPtr fptr = &IsLarger;
printf("Before sorting:\n");
PrintArray(arr, len);
BubbleSort2(arr, len, fptr);
// in ascending order
printf("After sorting:\n");
PrintArray(arr, len);
// a function pointer variable which points to the function IsLess()
fptr = ____Q5____;
printf("\nBefore sorting:\n");
PrintArray(arr, len);
BubbleSort2(arr, len, fptr);
// in descending order
printf("After sorting:\n");
PrintArray(arr, len);
return 0;
}
#endif
Welcome to point out the mistakes and faults!
Gitalking ...