
C++
xuxuxubao
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
邻接表建图
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<queue>using namespace std;#define MaxvertexNum 80#define INFINITY 65535struct DataType { int a, b, c;};typedef struc...原创 2019-09-25 23:17:33 · 314 阅读 · 0 评论 -
桥接模式
class Engine {public: virtual void InstallEngine() = 0;};class _4400ss:public Engine{public: virtual void InstallEngine(){ cout << "4400c发动机"<< endl; }};class _4500ss :public E...原创 2019-05-10 21:14:21 · 204 阅读 · 0 评论 -
代理模式&&装饰模式
一.代理模式class Subject{public: virtual void sailbook() = 0;};class RealSubjectBook {public: virtual void sailbook() { cout << "实体店卖书" << endl; }};class dangdang :public Subjec...原创 2019-05-10 16:32:23 · 136 阅读 · 0 评论 -
原型模式
一个复杂的对象,具有自我复制的功能class Person {public: virtual Person *clone()=0; virtual void prinT()=0;};class CPlusProgrammer :public Person{public: CPlusProgrammer() { this->m_name = ""; this-&...原创 2019-05-10 15:05:57 · 114 阅读 · 0 评论 -
建造者模式
#include<iostream>#include<stdio.h>using namespace std;#include<string>//对象的表示class House {public: void setFloor(string floor) { this->m_floor = floor; } void setW...原创 2019-05-10 13:39:41 · 108 阅读 · 0 评论 -
责任链模式
该模式构造一系列分别担当不同职责的类的对象来共同完成一个任务,这些类的对象之间像链条一样紧密相连,所以被称为责任链模式。class CarHandle {public: virtual void HandleCar()=0; CarHandle* setnextHandle(CarHandle *handle) { this->m_carhandle = handle; ...原创 2019-05-15 11:54:27 · 266 阅读 · 0 评论 -
哈夫曼树的构造
每次把权值最小的两颗二叉树合并typedef struct TreeNode *HuffmanTree;struct TreeNode{ int weight; HuffmanTree left,right;}HuffmanTree Huffman(MinHeap H){ int i;HuffmanTree T; BuildMinHeap(H)//...原创 2019-05-07 20:25:36 · 322 阅读 · 0 评论 -
命令模式
#include<list>class Doctor {public: void treat_eye() { cout << "医生治疗眼睛" << endl; } void treat_nose() { cout << "医生治疗鼻子" << endl; }};class Command {public:...原创 2019-05-14 23:06:01 · 163 阅读 · 0 评论 -
模板模式
class MakeCar {public: virtual void MakeHead() = 0; virtual void MakeBody() = 0; virtual void MakeTail() = 0;public: void make() { MakeHead(); MakeBody(); MakeTail(); }private:};cla...原创 2019-05-14 22:46:40 · 119 阅读 · 0 评论 -
简单工厂模式和工厂模式
(简单工厂模式不是标准的设计模式)class Fruit{public: virtual void getFruit()=0;}class Banana:public Fruit{public: virtual void getFruit() { cout<<"我是香蕉"<<endl; }};clas...原创 2019-05-09 23:11:12 · 279 阅读 · 0 评论 -
设计模式C++ (基本原则)
1.设计模式的基本原则:开放封闭原则:类的改动应该是通过增加代码实现而不是更改代码class BankWorker{public: void save(){cout<<"存款"<<endl;} void moveM(){cout<<"转账"<<endl} void giveM(){cout<<"缴费"...原创 2019-05-09 21:09:49 · 178 阅读 · 0 评论 -
策略模式
class Strategy {public: virtual void crypt() = 0;};class AES :public Strategy{public: virtual void crypt() { cout << "AES加密算法" << endl; }};class DES :public Strategy {public:...原创 2019-05-15 23:14:54 · 153 阅读 · 0 评论 -
组合模式&&外观模式
组合模式#include<list>class IFile {public: virtual void display() = 0; virtual int add(IFile *ifile) = 0;//添加一个文件 virtual int remove(IFile *ifile) = 0;//移除一个文件 virtual list<IFile *>* ...原创 2019-05-12 13:31:35 · 422 阅读 · 0 评论 -
享元模式
#include "map"class Person{public: Person(string name, int age) { this->m_name = name; this->age = age; } virtual void printT() = 0;protected: string m_name; int age;};class...原创 2019-05-12 15:22:41 · 109 阅读 · 0 评论 -
关于单例模式的写法理解
class MyCas{private: MyCas() { }private: static MyCas *m_instance;public: static MyCas *Getinstance() { if (m_instance == NULL) { m_instance = new MyCas(); static cGarhuishou c1; }...原创 2019-08-17 11:33:13 · 225 阅读 · 0 评论 -
socket(C++)客户端和服务端
服务端#define _WINSOCK_DEPRECATED_NO_WARNINGS#include<WinSock2.h>#include<stdio.h>#define PORT 5150#define MSGSIZE 1024#pragma comment(lib,"ws2_32.lib")void main(){ //1.初始化 WS...原创 2019-06-20 11:37:00 · 562 阅读 · 0 评论 -
C++调用Mysql
#define _CRT_SECURE_NO_WARNINGS#include "stdio.h"#include <mysql.h>int main(){ MYSQL * con; //= mysql_init((MYSQL*) 0); MYSQL_RES *res; MYSQL_ROW row; char tmp[400]; //database confi...原创 2019-06-02 09:36:36 · 225 阅读 · 0 评论 -
迭代器模式
#include <iostream>using namespace std;// MyIterator Aggregate ContreteIterator ConcreteAggregate// a b c d// ▲typedef int Object ;#define SIZE 5 class MyIterator{public:...原创 2019-05-17 21:22:12 · 154 阅读 · 0 评论 -
解释器模式
#include <iostream>using namespace std;// Context // Expression // PlusExpression MinusExpression class Context{public: Context(int num) { this->m_num = num; } int getNum(...原创 2019-05-17 20:39:43 · 112 阅读 · 0 评论 -
状态模式
#include <iostream>using namespace std;class Worker;class State{public: virtual void doSomeThing(Worker *w) = 0;};class Worker{public: Worker(); int getHour() { return m_hour;...原创 2019-05-17 17:52:38 · 116 阅读 · 0 评论 -
访问者模式
#include<string>#include<list>class Park;class Visitor {public: virtual void visit(Park *park) = 0;};class Park {public: Park(string name) { this->ParkName = name; } strin...原创 2019-05-17 15:55:10 · 108 阅读 · 0 评论 -
备忘录模式
#include <iostream>using namespace std;#include "string"//Caretaker 管理者// MememTo 备忘录class MememTo{public: MememTo(string name, int age) { m_name = name; m_age = age; } string...原创 2019-05-17 15:01:49 · 117 阅读 · 0 评论 -
观察者模式
适用于:定义对象间一对多的依赖关系,使得每一个对象改变状态,则所有以来于他们的对象都会得到通知#include<list>class Secretary;//观察者class PlayerObserver {public: PlayerObserver(Secretary *secretary) { this->m_secretary = secret...原创 2019-05-17 13:32:02 · 230 阅读 · 0 评论 -
中介者模式
class Mediator;class Person{public: Person(string name, int sex, int condi,Mediator *mediator) { m_name = name; m_sex = sex; m_condi = condi; m_mediator = mediator; } string getName()...原创 2019-05-16 21:40:08 · 102 阅读 · 0 评论 -
单向链表逆置操作
1.主要是利用头插法,先初始化一个空的逆置链表,再按顺序遍历原始链表,根据头插法来填充逆置链表typename struct Node{ int data; Node *next;} //链表逆置Node *reverse_list(Node *ls){ Node *p,*q; p=ls->next; ls->next=NULL...原创 2019-05-01 15:57:22 · 263 阅读 · 0 评论 -
单向链表基本操作
struct list{ int data; struct list *next;}//节点定义//创建一个节点struct list *create_list(){ return calloc(sizeof(struct list),1);}//遍历链表void traverse_list(struct list *s){ struct list...原创 2019-05-01 14:19:50 · 167 阅读 · 0 评论 -
图
邻接矩阵表示图:1.图(邻接矩阵)初始化typedef struct GNode *PtrToGNode;struct GNode{ int Nv; int Ne; WeightType G[MaxVertexNum][MaxVertexNum];};typedef PtrToGNode MGraph;typedef int Vertex;MGrap...原创 2019-05-08 16:17:09 · 106 阅读 · 0 评论 -
C++复习笔记(五)主要是模板部分
1.函数模板:template <typename T>void myswap(T &a,T&b) { T c; c=a; a=b; b=c;} //函数模板调用 void main(){ int x=10,y=20; char a='a',b='b'; myswap<int>(x,y);//显示类型调用 myswap<...原创 2019-04-07 10:25:44 · 137 阅读 · 0 评论 -
C++ 优先队列(priority_queue)
既然是队列那么先要包含头文件#include <queue>, 他和queue不同的就在于我们可以自定义其中数据的优先级, 让优先级高的排在队列前面,优先出队和队列基本操作相同:top 访问队头元素empty 队列是否为空size 返回队列内元素个数push 插入元素到队尾 (并排序)emplace 原地构造一个元素并插入队列pop 弹出队头元素swap 交换内容...转载 2019-03-31 11:10:07 · 154 阅读 · 0 评论 -
C++基础复习笔记(二)
1.()括号运算符的重载:class A{ public: int operator (int a, int b) { return a*a+b*b; } int sumfunction(int a,int b) { return a+b; }}int main(){ A(2,3); A.sumfunction(2,3);//区别 }2.纯...原创 2019-03-22 17:00:37 · 92 阅读 · 0 评论 -
(C++)strcmp函数的使用
函数关键字:strcmp使用格式:类型 strcmp(参数1,参数2)功 能: 比较参数1和参数(1、若参数1>参数2,返回正数;2、若参数1<参数2,返回负数;3、若参数1=参数2,返回0;)可以理解为比较字符串是否相等,参数一减去参数二。...原创 2019-03-25 14:42:40 · 1799 阅读 · 0 评论 -
C++基础复习笔记(四)
c中没有字符串 字符串类(c风格的字符串)//Mystring.hclass Mystring{public: Mystring(); Mystring(const char* p); Mystring(const Mystring& s); ~Mystring(); //重载等号操作符 Mystring& operator=(const char *p); ...原创 2019-03-25 11:30:22 · 98 阅读 · 0 评论 -
C++基础复习笔记(三)
1.new和delete的用法 :对比malloc freeint *p=new int;//分配基础类型int *p=new int(30);//初始化为30delete p;int *q=new int [10];//分配数组变量delete [] q;//分配对象的class Test{private: int a;public: Test(int _a){ th...原创 2019-03-25 10:24:35 · 92 阅读 · 0 评论 -
C++基础复习笔记(一)
**1.父类的private成员再子类中依然存在,但是子类是无法访问的。不论何种方式继承基类,派生类都不能直接使用基类私有成员。2.对protected成员的理解就是,可以在类内包括派生类进行访问,类外是无法访问的。3.类型兼容性原则是指再需要基类对象的任何地方,都可以用共有派生的子类对象来代替。通过公有继承,派生类得到了基类中除构造函数析构函数之外的所有成员。4.基类定义的指针,同样可以指...原创 2019-03-21 13:13:50 · 103 阅读 · 0 评论 -
字符串与整型相互转换
#include <iostream>#include <sstream>using namespace std;int main(void){ stringstream ss; int i=0; for(i=0;i<=100;i++) { ss<<i; } string s=ss...原创 2018-09-11 10:33:01 · 1872 阅读 · 0 评论 -
C++数据结构学习笔记(2)
归并排序法template <typename T>//将arr[l...mid]和arr[mid+1...r]两部分合并void __merge(T arr[],int l,int mid,int r){ T aux[r-l+1]; for(int i=l;i<+r;i++) aux[i-l]=arr[i];//aux[]索引是从0...原创 2018-07-29 17:00:55 · 157 阅读 · 0 评论 -
比赛笔记记录
unordered_map<int,int>road2index,cross2index,car2index,index2road,index2cross,index2car;//为了和练习地图id一致void ReOrderData(){ /***建立id映射关系***/ for(int i=0;i<road_num;i++){ int ro...原创 2019-04-02 15:17:49 · 136 阅读 · 0 评论 -
二叉树的遍历
1.先序遍历:先根节点,再左子树,最后右子树2.中序遍历:先左子树,再根节点,最后右子树3.后序遍历:先左子树,再右子树,最后根节点先序遍历算法DLR(NODE *root){ if(root!=NULL)//先 { printf("%d",root->data); DLR(root->lchild);//递归遍历左子...原创 2019-04-18 16:48:15 · 146 阅读 · 0 评论 -
二叉树的基本操作
计算二叉树的叶子节点写法一:int countLeaf(BiNode *root){ int count=0; if(root) { if(root->lChild==NULL && root->rchild==NULL) { count++; } i...原创 2019-04-18 12:21:49 · 181 阅读 · 0 评论 -
用数组来建立一个最小堆
#define MaxN 1001#define MinH -10001int H[MaxN],size;void Creat(){ size=0; H[0]=MinH;//堆都是从下标为1开始的,在0处设置一个哨兵,最小值。}void Insert(int x){ int i; for(i=++size;H[i/2]>x;i/=2) ...原创 2019-05-08 10:34:20 · 1238 阅读 · 0 评论