C++
lumaomao_
哈哈哈哈哈哈哈哈
展开
-
讨论nullptr和NULL
最近玩了两天的c++11,其中有一个是新的关键字nullptr。 这里讨论下nullptr的存在价值,应用场景以及不支持c++11的时候如何模拟nullptr。 1、为什要有nullptr 我们给一个指针赋初值的时候一般这么写 FILE* fp = NULL; 这里有个NULL的定义,一般情况下它是这么定义的: [cpp转载 2014-10-18 22:06:26 · 338 阅读 · 0 评论 -
排序
/*=======================基数排序的实现===========================*/ typedef struct { int data; int next; }node; int head=0; int fr[10]; int re[10]; void Distribute(node *a, int w) //第一次w=1 { in原创 2015-01-28 17:08:47 · 321 阅读 · 0 评论 -
最短路径的实现
#include int main() { int i,j,bflag,temp,min,r; int {1,4,1,1,0,0,0,0}, //g[i][i]=1表示点i属于集合A {2,0,6,0,1,0,0,0}, //g[i][i]=0表示点i不属于集合A {原创 2015-01-28 17:07:54 · 420 阅读 · 0 评论 -
图的实现
//有向图的创建,遍历,复制,查询 #include #include #define MAX_VERTEX_NUM 10 typedef struct { int vexnum; //顶点个数 int A[MAX_VERTEX_NUM][MAX_VERTEX_NUM]; }Grape; //邻接矩阵初始化有向图 void Create_Grape(Grape &G) { ch原创 2015-01-28 17:06:21 · 389 阅读 · 0 评论 -
哈夫曼编码
#include #include using namespace std; typedef struct { unsigned int weight; //权值 unsigned int parent,lchild,rchild; //父母和孩子指针 }HTNode,*HuffmanTree; //动态分配数组存储赫夫曼树原创 2015-01-28 17:05:25 · 396 阅读 · 0 评论 -
二叉树的实现
typedef struct node{ char data; struct node *lchild,*rchild; }BinTNode,*BinTree; //自定义二叉树的结点类型 int NodeNum,leaf; //NodeNum为结点数,leaf为叶子数 //基于先序遍历算法创建二叉树 //要求输入先序序列,其中加入原创 2015-01-28 17:03:29 · 338 阅读 · 0 评论 -
数组(稀疏矩阵)
typedef struct { int i,j; int value; }Triple; typedef struct { Triple data[MAXSIZE]; int rpos[MAXRC]; int row,col,num; }XiShuArray; int triarray(XiShuArray &M) // 创建一个稀疏矩阵; // 输入行数、列数原创 2015-01-28 17:01:12 · 723 阅读 · 0 评论 -
括号匹配(栈)
#include #include #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; typedef char SElemType; typedef struct { SElemType *base;原创 2015-01-28 16:58:04 · 437 阅读 · 0 评论 -
链表的实现
#include #include #define OK 0 #define ERROR 1 #define OVERFLOW 2 typedef int Status; typedef int ElemType; typedef struct LNode { ElemType data; LNode *next; }LNode,*Linklist; bool InitList(Lin原创 2015-01-28 16:56:22 · 296 阅读 · 0 评论 -
顺序表的实现
#include #include #include #define MAXSIZE 100 using namespace std; //学生类 typedef struct Students_List { int num; string name; float score; }; void input_message(Students_List &S) { cout<<"请输原创 2015-01-28 16:54:45 · 414 阅读 · 0 评论 -
牛顿迭代法
//牛顿迭代法的实现 #include #include using namespace std; double f(double x) { return exp(x)+10*x-2; } double f1(double x) { return exp(x)+10; } void NDDA(double x0,double e,int N) { int k=1,I; doub原创 2015-01-26 16:11:49 · 529 阅读 · 0 评论 -
整数划分
//整数划分问题的实现#include using namespace std; int q(int n,int m) { if((n<1)||(m<1)) return 0; if(n==1||m==1) return 1; if(n<m) return q(n,n); if(n==m) return q(n,m-1)+1; return q(n,m-1)+q(n-m原创 2015-01-26 16:10:01 · 311 阅读 · 0 评论 -
二分查找
#include using namespace std; #define MAXSIZE 1000 template //在n个数中使用二分查找 int BinarySearch(Type a[],const Type& x,int n) { int left=0;int right=n-1; while(left<=right) { int middle; middle=(lef原创 2015-01-28 16:16:52 · 515 阅读 · 0 评论 -
C++ template
c++集合了过程式语言,通用语言,面向对象语言的众多特点。模板是通用语言的特性,模板又叫参数化类型(parametrized types)。 使用模板可以使用户为类或者函数声明一种一般模式,使得类中的某些数据成员或者成员函数的参数、返回值取得任意类型。 使用模版的好处:我们可以利用模版编写和数据类型无关的代码,而不需要进行频繁的类型转化 注意事项:模板的声明或定义只能在全局,命名空间或类范围原创 2015-01-28 14:17:03 · 332 阅读 · 0 评论 -
二分法的实现
哈哈哈//二分法的实现 #include #include using namespace std; void binary(double a,double b,double c); double f(double x) { return (exp(x)+10*x-2); } int main() { double a,b,c; cout<<"输入一个零点所在区间:(a,b):";原创 2015-01-26 15:32:39 · 526 阅读 · 0 评论 -
Hanoi问题
#include using namespace std; void Hanoi(int n,char a,char b,char c) { if(n>0) { Hanoi(n-1,a,c,b); cout" Hanoi(n-1,b,a,c); } } int main() { int n; cout cin>>n; Hanoi(n,'A','B','C'); }原创 2015-01-26 15:14:29 · 655 阅读 · 0 评论 -
职工管理系统的开发(C++)
本人只提供部分代码,意在学习交流,切勿拿来主义复制粘贴。转载需指明出处! #define MAXSIZE 100 //存储员工的人数的最大值 int i; //计数器,全局变量 //生日类 class Birthday { private: int year,month; public: void setBirthday() { cin>>year; cin>>m原创 2015-01-28 16:39:09 · 547 阅读 · 0 评论