- 指针练习:MyMax
♥茶♥叶♥的♥讲♥解♥
- 2024-11-25 13:40:37 @
// 比较内容指针 内存大小 长度 比较函数
void * MyMax(void * a, int width, int num, int (*compare)(void * p1, void * p2)) {
void * result = a; // 指向内容指针的指针,用来参加比较函数 ↖result的位置
for (int i = 1; i < num; ++i) // 循环遍历数组
{
if(compare(result, ((char *) a ) + i * width) < 0) // 比较函数比较
result = ((char *)a) + i * width; // 如果找到更大的就将result设为更大的值(result = max(result, xxx)的效果)
}
return result; // 虽然是void但因为是void指针函数,所以有返回值
}
1 comments
-
C24liukaiwen LV 7 @ 2024-11-26 18:46:02
看不懂
- 1
Information
- ID
- 925
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 75
- Accepted
- 26
- Uploaded By