用C++语言改编了一个python版本的艺术画opengl实现,代码与效果如下感觉用c++绘制速度就是快#include <math.h>
#include <GL/glut.h> int W, H, R;void init() {glClearColor(1, 1, 1, 1);
}void drawFunc() {float r;glClear(GL_COLOR_BUFFER_BIT);glColor3f(0, 0, 0);glBegin(GL_POINTS);for(float x = -R; x <= R; x += 0.04) {for(float y = -R; y <= R; y += 0.04) {r = cos(x) + sin(y);glColor3f( cos(y * r), cos( x *...
// 实现运算符的重载#include <iostream>
using namespace std;class Int
{public:Int(int i = 0) :m(i){cout << "constructed function" << endl;}~Int(){cout << "destructor" << endl;}public:Int operator+(const Int &d);Int operator-(const Int &d);Int operator*(const Int &d);Int operator/(const Int &d);Int operator|(const Int &d);Int operator&(const Int &d);Int operator^(const Int &d);Int operator~();Int op...
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace tx
{struct ST{publicchar c1;publicint x;publicint y;}class Ct{[DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]publicstaticexternvoid MemCopy(byte[] dest, byte[] src, int count);//字节数组到字节数组的拷贝[DllImport("msvcrt.dll", EntryPoint = "memcpy", Cal...
今天实现了下链表的基本操作,包括节点的创建,头插尾插,头删尾删,一次遍历寻找链表的中间节点,寻找链表的倒数第x个节点,删除无头链表的非尾节点,链表的逆置,代码如下:#include "SLinkList.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void PrintList(SListNode* pHead)//从指针位置打印链表
{
while (pHead)
{
printf("->%d", pHead->data);
pHead = pHead->next;
}
printf("\n");
}
static SListNode...
汇编的学习需要掌握一些基本的汇编指令,也要了解汇编的格式,今天采用c语言内嵌汇编的形式实现了简单的加法运算。 1 #include "stdafx.h" 2 3int main(int argc, char* argv[])4{5int a = 1;6int b = 2;7int c;8 _asm{9 mov eax,a
10 mov ebx,b
11 add eax,ebx
12 mov c,eax;
13 }
14 printf("a+b=%d\n",c);
15return0;
16 } 原文:https://www.cnblogs.com/justinyee/p/12293153.html
1// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。2//3 4 #include "stdafx.h" 5 #include"iostream" 6usingnamespace std;7 8 typedef int data;9 10 typedef struct node_list11{12 data info;;13 node_list *next;14}node;15 16 node *init();17 node *insert_head(node *head, data x);18 node *insert_rear(node *head, data x);19 node *insert_x(node *head, data x, data y);20 node *del_x(node *h...
描述:约瑟夫问题:有n只猴子,按顺时针方向围成一圈选大王(编号从1到n),从第1号开始报数,一直数到m,数到m的猴子退出圈外,剩下的猴子再接着从1 开始报数。就这样,直到圈内只剩下一只猴子时,这个猴子就是猴王,编程求输入n,m后,输出最后猴王的编号。输入:每行是用空格分开的两个整数,第一个是 n, 第二个是 m ( 0 < m, n < 300)。最后一行是: 0 0输出:对于每行输入数据(最后一行除外),输出数据也是一行,即最...
1.冒泡排序冒泡排序是O(N^2)复杂度的排序算法,效率较低,需要N趟遍历,每次将候选集中最小的数通过交换浮到最上面;template <typename Type>void BubbleSort(vector<Type> &arraySort, int lowIndex, int hightIndex){ bool bChange; for (int i=lowIndex; i<hightIndex; ++i) { bChange = false; for (int j=hightIndex; j>i; --j) { if (arraySort[j-1] > arraySort[j]) ...
一、关于Quicksort的简单介绍Quicksort算法属于divide and conquer算法,核心思想是取array中的一个元素作为pivot,然后把array除了pivot的其他元素与这个pivot进行比较,比pivot小的元素放在pivot左边,比pivot大的元素放在pivot的右边,我们就得到了两个subarray(左边和右边),然后再对新的subarray进行同样的操作,直到得到新array中只有一个元素。二、quicksort的C++程序实现://// main.cpp
// quicksort
//// Created b...
WeatherData.h 1#ifndef WEATHERDATA_H_INCLUDED2#define WEATHERDATA_H_INCLUDED3 4 #include <set>5 #include "Display.h" 6 7class WeatherData8{9public:
10void measurementsChanged();
11void registerObserver( Display *p_display );
12void removeObserver( Display *p_display );
1314private:
15int getTemperature() { return25; }
16int getHumidity() { return90; }
17int getPressure() { return120; }
1819 st...
# include<iostream>
#include<stdio.h>usingnamespace std;void maopao(int *list){int i,j,temp;for(i=0;i<9;i++){for(j=0;j<9-i;j++){if(list[j]>list[j+1]){temp = list[j];list[j] = list[j+1];list[j+1] = temp;//用于检测每一步的输出/* cout<<"i等于"<<i<<"j等于"<<j<<endl;for(int temp=0;temp<10;temp++){cout<<list[temp]<<" ";}cout<<endl;*/}}}
}int main(){int list[10];int n =9,m=0,i;cout<<"input 10 number"<<e...
SDK.h 1#ifndef SDK_H2#define SDK_H3 4 #include "AsyncProxy.h" 5 #include "Module.h" 6 #include <map>7 #include <vector>8 #include <string>9using std::map;
10using std::vector;
11using std::string;
121314class SDK
15{
16private:
17 vector<Module*> m_modules;
18 AsyncProxy* mp_asyncProxy;
19 map<string,Method*> m_methodIndex;
20private:
21 Method* checkMethod(string methodName, map<s...
在之前的博文中,介绍了图的深度优先遍历,并分别进行了递归和非递归实现。BFS 无法递归实现,最广泛的实现是利用队列(queue)。这与DFS的栈实现是极其相似的,甚至代码几乎都很少需要改动。从给定的起点节点开始,依次将其邻接节点全部塞入队列,每次访问一个节点时将其pop()出队列,并将其邻接节点也塞入队列。直到队列为空,算法结束。 代码实现并无太大障碍,c++实现: 1 #include <iostream>2 #include <queue>3usingnam...
一、UML图二、概念解释器模式(interpreter):给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。三、说明包含哪些角色?(1)AbstractExpression(抽象表达式):声明一个抽象的解释操作,这个接口为抽象语法树中所有的节点所共享。(2)TerminalExpression(终结符表达式):实现与文法中的终结符相关联的解释操作。实现抽象表达式中所要求的接口,主要是一个interpreter()方...
1 #include<iostream>2usingnamespace std;3 4//二叉树节点 5struct BinaryNode6{7char ch;8 BinaryNode* lchild;9 BinaryNode* rchild;
10};
11int HeightTree(BinaryNode* root);
12//初始化二叉树13void CreateBinaryTree() {
14 BinaryNode node1 = { ‘A‘,NULL,NULL };
15 BinaryNode node2 = { ‘B‘,NULL,NULL };
16 BinaryNode node3 = { ‘C‘,NULL,NULL };
17 BinaryNode node4 = { ‘D‘,NULL...