C++二分查找算法演示代码#include <cstdio>/* * 传统的二分查找,数组有序且没有重复 */int binary_S(int *a, int n, int key){ int l = 0, r = n-1; int mid; while (l <= r){ mid =……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1685浏览 2791个赞
C++实现奇数魔方阵/* 魔方阵,古代又称“纵横图”,是指组成元素为自然数1、2…n的平方的n×n的方阵, 其中每个元素值都不相等,且每行、每列以及主、副对角线上各n个元素之和都相等。 输入一个奇数,实现奇数魔方阵。 附:奇数魔方阵的实现方法 (1) 将1填入第一行中间; (2……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2478浏览 580个赞
霍夫曼编码(Huffman Coding)是一种编码方式,是一种用于无损数据压缩的熵编码(权编码)算法。1952年,David A. Huffman在麻省理工攻读博士时所发明的,并发表于《一种构建极小多余编码的方法》(A Method for the Construction of Minimum-Redundancy Codes)一文。在计算机数据处理中,……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2981浏览 2608个赞
一个简单的C++调用动态库的实例转自:http://blog.csdn.net/lxh1230119/article/details/8071730 先创建一个动态库dll工程工程中添加 dlltest.cpp  dlltest.d……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3096浏览 2673个赞
C++数字转换代码片段#include "stdafx.h"#include <iostream>#include <string>#include <functional>using namespace std;void id2gid(long id,char* pszID){ ……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3238浏览 1871个赞
C++操作mysql数据库范例代码#include <my_global.h>#include <mysql.h>void TestMySQL(){ TRACE("MySQL client version: %s\n", mysql_get_client_info()); MYSQL *conn =……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2721浏览 2374个赞
C++计算用户打字速度#include <stdio.h>#include <dos.h>#include <conio.h>#define ESC 0x1b#define BSPACE 0x08const unsigned long far * const dosTime = (co……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1846浏览 507个赞
C++实现二分查找算法的代码<<array binary search>>=template< typename T, typename compare_less >int array_binary_search(T a[], int low, int high, T target) { while (l……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3368浏览 964个赞
C++冒泡法排序算法演示代码#include <algorithm> template<typename Iterator> void bubbleSort(Iterator first, Iterator last) { Iterator i, j; for (i = first; i……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2689浏览 1760个赞
C++计算倒数的代码#include <iostream> using namespace std; class Var; class Base { public: virtual ~Base() {}; virtual const Base *clone() = 0; virtua……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2987浏览 1591个赞
C++添加字符串到文件#include <iostream> #include <fstream> int main() { std::ofstream out("filename", std::ios::app); out << "aString"……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2458浏览 1430个赞
C++版的快速排序法#include <functional>#include <algorithm>#include <iterator>template< typename BidirectionalIterator, typename Compare >void quick_sort( Bi……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2671浏览 1273个赞
C++读取文件到字节数组#include <iostream> #include <fstream> char* readFileBytes(const char *name) { ifstream fl(name); fl.seekg( 0, ios::end ); siz……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3460浏览 2163个赞
KMP算法实现字符串搜索#include<stdio.h>#define maxsize 100typedef struct string{ int n; char s[maxsize];}string;int get_nextval(string &T,int nextval[]){ int i=1; in……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2520浏览 2754个赞
C++归并排序算法 *MERGE-SORT */#include<cstdlib>#include<limits>#include<iostream>#include<vector>#include<iomanip>using namespace std;typedef vec……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1683浏览 2150个赞
C++堆排序代码演示/*6 堆排序 *HEAP-SORT */#include<cstdlib>#include<iostream>#include<vector>#include<iomanip>using namespace std;typedef vector<int>:……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1564浏览 269个赞
C++全排列实现代码 思路1——全排列的递归实现核心思想:比如对于字符串”abc”,第一步:求所有可能出现在第一个位置的字符即:a,b,c。使用方法:把第一个字符和后面的b、c字符进行交换。第二步:把第一个字符后面的所有字符仍然看成两部分,即后面的第一个字符及除此之外的其他字符……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2459浏览 101个赞
自己一直想做一个和windows资源管理器一样的程序,所以看了一下如何列举系统的所有进程。主要用到几个函数CreateToolhelp32Snapshot,Process32First,Process32Next和一个结构体PROCESSENTRY32。其中用法可以看百度百科或MSDN#include <windows.h> #incl……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1714浏览 179个赞
C++求字符串最长连续字符的长度#include<assert.h> int get_max_char_count(char *s,char *ret) { assert(s!=NULL); char *temp_char,*final_char,*p; int temp_count,final……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2153浏览 1221个赞
C++顺序表操作代码演示/**建立一个顺序表,插入n个元素并输出*Author :CplusHua PurpleHua*Date:2012-10-06*/#include<iostream>#include "malloc.h"#include <stdio.h>#define ElemTyp……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2720浏览 2718个赞
我们都知道病毒木马都要与外面通信,如何检测呢,今天我们来时间检测进程端口来检测木马#include <windows.h>#include <Tlhelp32.h>#include <winsock.h>#include <stdio.h>#pragma comment(lib, "ws……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3188浏览 1651个赞
NtTerminateProcess 、NtResumeProcess 、NtSuspendProcess这三个函数是微软内核api可以在线查询*++Module Name:NtSuspendProcess.cppAbstract:This utility [Suspend|Resume] processes.Author:Michael ……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3306浏览 1706个赞
C++算法输出链表倒数第k个元素 链表结点定义如下:  struct ListNode{ int m_nKey; ListNode* m_pNext;};/*-----------------------------Copyr……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2033浏览 2369个赞
转自:……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2054浏览 2499个赞
C++ sprintf函数详解 函数功能: 把格式化的数据写入某个字符串头文件: stdio.h函数原型: int sprintf( char *buffer, const char……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2333浏览 2870个赞
const:常量限定修饰符,它把一个对象转换为常量(constant)。const对象必须初始化而且是在定义的同时。初始化后的const对象(或指针)是不能修改的。 例1:int i = 0; const int j = 0; // int const j = 0; ……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2062浏览 1536个赞
VC获取本机网卡地址 如何获取网卡地址(MAC地址):VC++编写的代码,适用于windows环境,API实现/*char *pMACAdr,返回网卡地址的buff, int *nBuffLen前一个参数的长度, int nAdapterID = 0网卡号,针对多网卡问题,有……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3384浏览 659个赞
一个简单的C++随机产生彩票号码的代码#include <stdio.h>#include <stdlib.h>#include <time.h>#include <stdbool.h>using namespace std;bool checkequal(int *a,int b);void……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2471浏览 1559个赞
C++顺序存储的线性表来源:http://blog.csdn.net/creazyapple/article/details/7931830/* * 顺序存储的线性表 */#include <stdio.h>#define OK 1#define ERR 0#define LIST_INIT_SIZE 100#define L……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2812浏览 1324个赞
派生类不能直接访问基类的私有成员,若要访问必须使用基类的接口,即通过其成员函数。实现方法有如下两种:1.在基类的声明中增加保护成员,将基类中提供给派生类访问的私有成员定义为保护成员。2.将需要访问基类私有成员的派生类成员函数声明为友元。#include<iostream>using namespace std;class Base{……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1671浏览 968个赞
日期字符转化成时间戳 时间戳转化成日期 /* @param date @param formart of date @return time_t @auth……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3025浏览 2353个赞
一个简单的C++编写的u盘病毒代码一个win32下能用的U盘病毒 研究原理可以 别编译拿去害人就行 (ring3的病毒貌似也害不了人) 前久用IDA逆向出来的 感兴趣的可以看看。。。#include<windows.h>#include<string.h> BOOL UDevice();void Reso……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2202浏览 1183个赞
前缀输入,中缀输出,若带字母,则为字母赋值,最后计算表达式的值。#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include<string.h>typedef enum{ INT, CHAR} DataType;//CHAR=1……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3461浏览 1805个赞
C++多线程复制文件使用文件读写复制问文件的线程函数:DWORD WINAPI CopyThread(LPVOID lpParam){ CCopyFileDlg *dlg=(CCopyFileDlg*)lpParam; CFile file1(dlg->m_Src,CFile::modeRead); CFile file2(dlg-&g……继续阅读 » 水墨上仙 5年前 (2021-03-24) 1461浏览 1484个赞
C++栈的链式存储演示代码#include<iostream>using namespace std;struct Data{ Data *next; int data;};class Link_Stack{private: Data *base; Data *top; int top1;public: Link……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2506浏览 2243个赞
C++解决大数据的加法、减法、乘法以及阶乘的计算问题来源:http://blog.csdn.net/complety/article/details/8276813  限于数据类型的长度有限,对于大数据的计算就无能为力了,这里主要是采用字符数组解决精度问题。……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3367浏览 2419个赞
OCILIB是一个跨平台的Oracle驱动程序,可提供非常快速和可靠地访问Oracle数据库。它提供了一个丰富,功能齐全,并易于使用的API 。OCILIB 支持运行的所有Oracle平台。#include "ocilib.h" int main(int argc, char *argv[]){ OCI_Connect……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2972浏览 1661个赞
C++在linux中的ctrl+c信号处理,判断用户是否按下了ctrl+cint main(int argc, char *argv[]){ signal(SIGINT, sig_int);//注册信号 捕获SIGINT(中断)信号,然后调用sig_int函数 (Ctrl-C会产生这个信号) return 0;}/*SIGINT信号截取函数*……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3115浏览 2913个赞
C++仿linux ls命令的实现代码#include <stdio.h>#include <stdlib.h>#include <dirent.h>#include <sys/stat.h>#include <string.h>#include <errno.h>#i……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2335浏览 650个赞
linux平台下mongodb c++连接池封装,线程安全//函数返回0:成功 >0 出错class cmongo{ public: //默认构造函数,默认连接数为1 cmongo(); //传入连接数到构造函数,默认连接数为size cmongo(int size); //析构函数 ~cmongo(); publi……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3292浏览 931个赞
linux C++连接数据库postgreSql,在centos6.3,eclipse下调试成功,其中需要设置一下eclipse的参数#include <stdio.h>#include <stdlib.h>#include <libpq-fe.h>int main(int argc, char * argv……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2682浏览 289个赞
C++在windows下获取本地主机ipv4地址和ipv6地址#include <Winsock2.h>#include <stdio.h>#include <iostream>#include <cstring>#include<ws2tcpip.h>#pragma comment……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2448浏览 1626个赞
求任意权值最短路径的Bellman-Ford算法C++实现Bellman-Ford算法可以用来解决所要求的最短路径的图中含有负数边的情形。算法的基本思想:如果两个结点间存在最短路径,那么这条路径中各个结点最多经过一次(因为如果超过一次,说明路径中有环,如果是正数环,会使路径权值增长;若为负数环,最短路径不存在;若为零环,不影响结果)。因此我们只需迭代n-1次……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3015浏览 572个赞
C++在linux下设置和获取事件的代码 时间函数 time_t time(time_t *t); char *asctime(const struct tm *tm); char *asctime_r(const struct tm *tm……继续阅读 » 水墨上仙 5年前 (2021-03-24) 3454浏览 553个赞
求最大网络流的C++实现(利用广度优先遍历的思想)基本思想:利用广度优先遍历的思路,从一个可行流(一般取零流)开始,不断进行标号过程和调整过程,直到找不到起点到终点的可增广路径为止。1、标号过程在这个工程中,网络上的点分为已标号点和未标号点。将起始点标号,其他刚开始未标号。从起始点开始,利用广度优先算法进行遍历,找到一个未标号点时,看临接的标号点与之是正向边……继续阅读 » 水墨上仙 5年前 (2021-03-24) 2565浏览 1068个赞