【修改的C++版Opengl艺术画实现】教程文章相关的互联网学习教程文章

栈的存储结构的实现(C/C++实现)【代码】【图】

存档 1 #include "iostream.h" 2 #include <stdlib.h>3#define max 204 typedef char elemtype;5 #include "stack.h" 6void main()7{8 stack s;9char x; 10 cout<<"(1)初始化栈s\n"; 11 initstack(s); 12 cout<<"(2)栈为"<<(stackempty(s)?"空":"非空")<<endl; 13 cout<<"(3)依次输入字母序列,以‘#‘结束"<<endl; 14 cin>>x; 15while(x!=‘#‘) 16 { 17 push(s,x); 18 cin>>x; 19 } 2...

循环链表的创建、插入、删除、逆序、显示(C++实现)【图】

对于单链表,因为每一个结点仅仅存储了向后的指针。到了尾标志就停止了向后链的操作,这样,其中某一结点就无法找到它的前驱结点了。 对于单链表的操作大家能够看我的这篇博客http://blog.csdn.net/zxnsirius/article/details/51183055我们将单链表中终端结点的指针端由空指针改为指向头结点,就使整个单链表形成了一个环。这样的头尾相接的单链表称为单循环链表,简称循环链表。以下是循环链表的综合操作的样例程序执行结果/*‘)...

通过c++11的condition_variable实现的有最大缓存限制的队列【代码】

通过condition_variable实现的有最大长度限制的队列:#include <condition_variable> #include <queue> #include <chrono> #include <iostream>/** 有最大队列个数限制*/// 参数T需要能够拷贝,而且拷贝不会存在副作用 template <typename T> class sync_queue { public:sync_queue(int queueMaxSize): m_queueMaxSize(queueMaxSize) { }// 处理数据线程template <typename Func>typename std::result_of<Func(T)>::type readQueue(F...

C++基础之指针与引用的底层实现

一句话总结指针分配内存,有地址(编译器和程序员看来),属于一个类型变量,支持取地址与解引用操作。引用分配内存,有地址(编译器看来),相当于一个变量别名,不支持取地址与解引用操作(即不可获取其本身地址),声明即必须初始化,不可变更引用对象,本质上是“pointer const”。推荐阅读快速理解:简谈 C++ 中指针与引用的底层实现原文:https://www.cnblogs.com/MinPage/p/14662084.html

C++职责链,策略,简单工厂综合实现

class Request;//职责链接口class Chain {protected: Chain* chain;public: Chain(Chain* chain = nullptr); virtual ~Chain() = 0; void setChain(Chain* chain) { this->chain = chain; } virtual void request(Request* request);}; Chain::Chain(Chain *chain) :chain(chain) {}Chain::~Chain() {}void Chain::request(Request* request) {   this->chain->request(request);}//请求接口class Request {public: enum class R...

C++实现将十进制数转换为小于等于九的任意进制【图】

//十进制转换为小于等于九的任意进制数 #include<iostream> #include<string> #include<stack>using namespace std;stack<int> num;void change(int N,int M) {if(N<0||M<=1){cout<<"error!"<<endl;return;}while(N>0){num.push(N%M);N/=M;}while(!num.empty()){cout<<num.top();num.pop();}cout<<endl; }int main() {for(;;){int N,M;//N代表十进制数,M代表任意机制(小于等于九进制)cout<<"输入十进制数 进制:";cin>>N>>M;cout<<...

c++ 实现双向链表【代码】

双向链表:#include<iostream> using namespace std;typedef struct list {int data;struct list *front;struct list *next; }List;List *head; //头结点 List *tail; //尾结点 int sum = 0;void push(int e) {List *p = new List;p->data = e;if(sum == 0){head = p;tail = p;p->front = NULL;p->next = NULL;}else{tail->next = p;p->front = tail;tail = p;p->next = NULL;}sum++; }void pop_back() {List *p = tail->front;p...

C++实现动态顺序表【代码】

#define _CRT_SECURE_NO_WARNINGS 1#include<iostream> using namespace std; #include<assert.h>typedef int DataType;class SeqList { public: SeqList() :_array(NULL ) , _size(0) , _capicity(0) {} SeqList(const SeqList & sList) :_array(new DataType [sList ._size]) , _size( ...

二叉树C++实现【代码】

二叉搜索树的代码实现,有插入、查找、删除等基本功能。需要注意的是,当类中有私有类pClass且在类外声明的成员函数的返回值是pClass类型的时候,需要在pClass前加typename。比如说template <typename Comparable> typename binarysearchtree<Comparable>::BinaryNode* binarysearchtree<Comparable>::findMax(BinaryNode* t)const {if (t == NULL) return NULL;if (t->right == NULL) return t;return findMin(t->right); }这里的...

FIFO算法与LRU算法的C++实现【代码】

#include <bits/stdc++.h> usingnamespace std; /*** FIFO算法的实现:其实是可以采用双端队列,然后限制一下* 双端队列的长度,根据我的限制应该是4。对于查询是否出现* 在这个队列里面,我们可以采用一个数组标记是否有存在。** 测试数据如下 16 4 0 1 2 4 3 4 5 1 2 5 1 2 3 4 5 6* **/struct FIFO{int len, m;///长度, len - 总访问数; m - 分配的物理块数int arr[105];///存储访问页面的编号deque<int>que;int vids[15];///标...

C++ 线性表实现【代码】

List.h #pragma once #include "targetver.h"#include <stdio.h> #include <tchar.h>#define LIST_INIT_SIZE 100 #define MAXSIZE 100typedef int ElemType;typedef struct Sqlist {ElemType * elem;int length;int listsize; }Sqlist, *ListPtr;typedef enum Status {success, fail, fatal, rangeerror,overflow }Status;Status List_Init(ListPtr L);void List_Destroy(ListPtr L);void List_Clear(ListPtr L);bool List_Empty(L...

【排序】堆排序,C++实现【代码】【图】

原创文章,转载请注明出处!博客文章索引地址博客文章中代码的github地址# 预备知识 堆是一种特殊的树形数据结构,即完全二叉树。堆分为大根堆和小根堆,大根堆为根节点的值大于两个子节点的值;小根堆为根节点的值小于两个子节点的值,同时根节点的两个子树也分别是一个堆。 # 基本思路步骤一:建立大根堆--将n个元素组成的无序序列构建一个大根堆,步骤...

grpc的简单用例 (C++实现)【代码】

这个用例的逻辑很简单, 服务器运行一个管理个人信息的服务, 提供如下的四个服务:(1) 添加一个个人信息  注: 对应于Unary RPCs, 客户端发送单一消息给服务器, 服务器返回单一消息(2) 添加多个个人信息  注: 对应于Client streaming RPCs, 客户端使用提供的stream发送多个消息给服务端, 等客户端写完了所有的消息, 就会等待服务器读取这些消息, 然后返回响应消息. gRPC保证在一次RPC调用中, 消息是顺序的.(3) 获取最多N个个人信息...

插入排序C++实现【图】

算法描述:从数组第二个元素开始向后扫描,将每个元素插到它前面所有元素的合适位置。下面给出整数数组的实现,对于其他复杂类型只需实现相应的自定义比较函数即可:#include <iostream> #include <math.h> using namespace std; const int Num=20; void exch(int* s,int a,int b) {int mid=s[a];for(int i=a;i>b;i--){s[i]=s[i-1];}s[b]=mid; } int main() { int array[Num]; int min=0; srand(2);//初始化随机数 for(int i=0;i<N...

10行C++代码实现高性能HTTP服务【代码】【图】

前言 是不是觉得C++写个服务太累,但又沉迷于C++的真香性能而无法自拔?作为一个老牌C++程序员(可以看我 github 上十几年前的C++项目:https://github.com/kevwan ),这几天听一个好友跟我聊起他写的C++框架,说极简代码即可完成各种C++服务的开发,不禁让我心生好奇!于是我去研究了一下,发现确实有点意思!实战(干货)话不多说,我们来一起看看,10行C++代码怎么实现一个高性能的Http服务,轻松QPS几十万。Linus说:talk is ...