算法公共头文件
来源:互联网 发布:chromebook装windows 编辑:程序博客网 时间:2024/04/27 20:55
/*
* Copyright (c) 2007 Lotomer
* 作 者 : Lotomer
* 文 件 名 : common.h
* 创建时间 : 2007.4.12
* 说 明 : 排序算法的公共部分
*/
/////////////////////////////////////////////////////////////////////////
#ifndef SORT_DEBUG
#define SORT_DEBUG
#endif
#ifdef SORT_DEBUG
#include <iostream>
using std::cout;
using std::endl;
template<class Elem>
void Print(Elem arr[], int nStart, int nEnd)
{
for (int i = nStart; i <= nEnd; ++i)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
#endif /* ifdef SORT_DEBUG */
//元素比较模板类
template<class T>
class Compare{
public:
virtual bool operator()(T& t1, T& t2) = 0;
};
//继承模板类
//小于
template<class T>
class Lower : public Compare<T>{
public:
bool operator()(T& t1, T& t2)
{
return t1 < t2;
}
};
//大于
template<class T>
class Greater : public Compare<T>{
public:
bool operator()(T& t1, T& t2)
{
return t1 > t2;
}
};
//-------------------------------------------------------
//交换元素
template<class Elem>
inline void swap(Elem arr[], int index_a, int index_b)
{
Elem tmp = arr[index_a];
arr[index_a] = arr[index_b];
arr[index_b] = tmp;
}
//重载
template<class Elem>
inline void swap(Elem &a, Elem &b)
{
Elem tmp = a;
a = b;
b = tmp;
}
//部分特化
template<class Elem>
inline void swap(Elem* a, Elem* b)
{
Elem* tmp = a;
a = b;
b = a;
}
* Copyright (c) 2007 Lotomer
* 作 者 : Lotomer
* 文 件 名 : common.h
* 创建时间 : 2007.4.12
* 说 明 : 排序算法的公共部分
*/
/////////////////////////////////////////////////////////////////////////
#ifndef SORT_DEBUG
#define SORT_DEBUG
#endif
#ifdef SORT_DEBUG
#include <iostream>
using std::cout;
using std::endl;
template<class Elem>
void Print(Elem arr[], int nStart, int nEnd)
{
for (int i = nStart; i <= nEnd; ++i)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
#endif /* ifdef SORT_DEBUG */
//元素比较模板类
template<class T>
class Compare{
public:
virtual bool operator()(T& t1, T& t2) = 0;
};
//继承模板类
//小于
template<class T>
class Lower : public Compare<T>{
public:
bool operator()(T& t1, T& t2)
{
return t1 < t2;
}
};
//大于
template<class T>
class Greater : public Compare<T>{
public:
bool operator()(T& t1, T& t2)
{
return t1 > t2;
}
};
//-------------------------------------------------------
//交换元素
template<class Elem>
inline void swap(Elem arr[], int index_a, int index_b)
{
Elem tmp = arr[index_a];
arr[index_a] = arr[index_b];
arr[index_b] = tmp;
}
//重载
template<class Elem>
inline void swap(Elem &a, Elem &b)
{
Elem tmp = a;
a = b;
b = tmp;
}
//部分特化
template<class Elem>
inline void swap(Elem* a, Elem* b)
{
Elem* tmp = a;
a = b;
b = a;
}
- 算法公共头文件
- 公共头文件
- 公共头文件耦合性的问题
- DES算法,头文件
- 我的算法头文件
- 内存池算法---头文件
- Algorithm 头文件中的算法
- html自适应公共头
- 我的算法头文件使用说明
- 单源最短路径BellmanFord算法头文件C++
- 公共文件
- 《UNIX环境高级编程》 —— 公共头文件 apue.h
- Gulp+webpack模板化开发演练(1):分离公共头文件
- 配合Dijkstra算法的二叉堆头文件C语言
- 配合Kruskal算法的二叉堆头文件C语言
- 配合Kruskal算法不相交集合头文件C语言
- 所有顶点间最短路径FloydWarshall算法头文件C++
- 最大流Edmonds-Karp算法头文件C++
- Ajax简介
- 模仿QQ的一个很帅的菜单栏
- Myspace中国,想说爱你并不容易
- J2EE模型Java 2 Platform, Enterprise Edition
- Murphy定律完整版
- 算法公共头文件
- javascipt操作xml文件
- 关联菜单效果
- 插入排序
- 语音聊天实现(Delphi)
- 数据库作业001:范式分析
- 房奴墓志铭
- 基于UML和ASP.NET实现三层B/S结构系统开发
- 冒泡排序