compare function overload
来源:互联网 发布:mac 设置分辨率 编辑:程序博客网 时间:2024/05/22 01:43
#include <stdio.h>#include <assert.h>
int cmp_int(const void *,const void *);
int cmp_doubl(const void *,const void *);
int cmp_char(const void *,const void *);
int cmp_str(const void *,const void *);
int cmp_function(int (*function)(const void *,const void *),/
const void *one,const void *two);
int main(void)
{
int a = 5;
int b = 4;
double a_double = 9.00;
double b_double = 20.00;
char a_char = '5';
char b_char = '5';
char *a_str = "abcdg";
char *b_str = "abcdf";
if ((cmp_function(cmp_int,&a,&b)) == 1)
printf("a > b/n");
else
printf("a <= b/n");
if ((cmp_function(cmp_doubl,&a_double,&b_double)) == 1)
printf("a_double > b_double/n");
else
printf("a_double <= b_double/n");
if ((cmp_function(cmp_char,&a_char,&b_char)) == 1)
printf("a_char > b_char/n");
else
printf("a_char <= b_char/n");
if ((cmp_function(cmp_str,a_str,b_str)) == 1)
printf("a_str > b_str/n");
else
printf("a_str <= b_str/n");
return 0;
}
int cmp_function(int (*function)(const void *,const void*),/
const void *one,const void *two)
{
return function(one,two);
}
int cmp_int(const void *one,const void *two)
{
if ((*((int *)one)) > (*((int *)two)))
return 1;
else
return 0;
}
int cmp_doubl(const void *one,const void *two)
{
if ((*((double *)one)) > (*((double *)two)))
return 1;
else
return 0;
}
int cmp_char(const void *one,const void *two)
{
if ((*((char *)one)) > (*((char *)two)))
return 1;
else
return 0;
}
int cmp_str(const void *one,const void *two)
{
char *temp_one;
char *temp_two;
temp_one = (char *)one;
temp_two = (char *)two;
while ((*temp_one != '/0') && (*temp_two != '/0')){
if (*temp_one > *temp_two)
return 1;
temp_one ++;
temp_two ++;
}
return 0;
}
- compare function overload
- function overload
- function overload 2
- TypeCast overload 和 function object
- C++ STL The compare function
- ActionScript中的Function和Constructor不能overload
- c++之-----重载函数overload function
- C++ friend template operator overload function
- C++笔记4--函数重载(function overload)
- C++ Can't Overload Static Function with Non-Static Function
- Compare the function: SQL server vs ORACLE
- c++ container with user defined compare function
- overload
- Overload
- Overload
- Overload
- 《C++ primer》学习笔记之三十二:function overload resolution概述
- How to create a File-Compare function in Visual C#
- Centos 网络基本设置
- 检测或设置是否为默认首页
- Ext:GridPanel 显示数据
- 使用拷贝构造函数与使用重载的“=”重载函数的区别
- CheckBox在ListView中导致其点击事件不会被触发解决方法
- compare function overload
- Qtopia2.1.1 在2410-S 上的移植
- Windows Mobile和Wince下使用TinyXML进行Native C++的开发
- 图表作文备忘
- 微笑是一种修养
- 放弃也是一种快乐
- 【转】Neutral Density (ND) Filters 中性灰色滤镜
- Notification和NotificationManager的基本使用方法
- Flex皮肤制作教程——修改组件的Skin