
算法集锦
文章平均质量分 73
u010856711
这个作者很懒,什么都没留下…
展开
-
一个用于读取应用程序配置文件(*.ini)的类
应用程序往往都有一个配置文件,在windows下,一般采用*.ini文件的方式,我们需要调用windows api来读取配置文件,api使用起来繁琐,笔者自己开发了一个读配置文件的类,使用十分方便,在使用的时候只需要实现具体的一个虚函数即可。#pragma once#include "string"#include "iostream"using namespace std原创 2013-06-08 15:36:38 · 1188 阅读 · 0 评论 -
冒泡排序 选择排序 插入排序
void swap(int &a, int &b){ int temp = a; a = b; b = temp;}//冒泡void sort0(int a[], int m){ for(int i=0; i<m-1; i++) { for(int j=0; j<m-i-1; j++) { if (a[j] < a[j+1]) { swap(a[原创 2014-03-04 14:12:46 · 914 阅读 · 0 评论 -
windows下实现socket 的 通讯的 select 模型
通讯端点定义类: #pragma once#include #define SERVER 1#define CLIENT 2#include using namespace std;class CEndpoint{public: CEndpoint(void); CEndpoint(SOCKET socket, unsigned原创 2013-12-31 18:09:36 · 1509 阅读 · 0 评论 -
以上两个文件的makefile
CC = g++CFLAGS = -Wallall: server clientclient: client.o $(CC) $(CFLAGS) -o $@ client.cpp -L/usr/lib64 -lsctpserver: server.o $(CC) $(CFLAGS) -o $@ server.cpp -L/usr/lib64 -lsctpclean原创 2013-09-03 11:01:06 · 1340 阅读 · 0 评论 -
SCTP 一对一模式(TCP)的服务器端代码
以下代码为基于sctp协议的一对一模式(TCP)的服务器端代码。#include #include #include #include #include #include #include #include #include const int buf_size = 1024; const int echo_port = 19000; char* usa原创 2013-09-03 10:54:19 · 2396 阅读 · 0 评论 -
SCTP 一对多模式 (UDP模式)的服务器端代码
以下源码是基于linux操作系统的。实现了基于SCTP模式的一对多模式的服务器端代码,不但处理的用户数据,而且处理了的通知类的消息,即notification消息。#include #include #include #include #include #include #include #include #include static void handle_e原创 2013-09-02 16:28:57 · 2687 阅读 · 0 评论 -
SCTP一对一模式(TCP)模式的客户端代码
#include #include #include #include #include #include #include #include #include const int buf_size = 1024; const int echo_port = 19000; char *usage_msg = "usage原创 2013-09-03 10:56:04 · 2022 阅读 · 0 评论 -
斐波那契数列
今天,去深圳一家公司参加面试,其中一道编程题目就是关于斐波那契数列的问题,回来后赶快把它实现。算是积累经验吧。当时使用递归方式实现的,回来后用非递归的方式也实现了一下。 // Challenge7.cpp : Defines the entry point for the console application.//#include "stdafx.h"//今天面试的一原创 2013-07-25 16:30:01 · 1130 阅读 · 0 评论 -
完全二叉树,知道总节点数,计算叶子结点的数量
昨天面试,有一道题是:完全二叉树,知道总节点数,计算叶子结点的数量。由于当时要求在纸上写代码,没有实际运行,所以回来后他这个代码调试一下.// Challenge8.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "math.h"//问原创 2013-07-26 10:13:15 · 7426 阅读 · 0 评论 -
财务上可能用得上整形数的读法
例如:1111,2222,3333 读作:一十一亿二千二百二十二万三千三百三十三#pragma onceclass CConvert{public: CConvert(void); virtual ~CConvert(void);public: bool getoutcome(char* result, char* input); static原创 2013-07-02 16:41:13 · 1204 阅读 · 0 评论 -
找出两个数组中满足给定和的数对
/*******************************************************************************************************************************************3.找出两个数组中满足给定和的数对问题描述:有两个数组arr1和arr2,两个数组均已经排好序,现在要找出这样的原创 2013-07-19 16:44:02 · 1812 阅读 · 0 评论 -
当数组中整形数连续时,求数组中唯一重复的整数
在现实生活中,我估计这个问题没有多大的意义, 但作为你一种方法,可以借鉴,也可以得出一个结论,那就是尽量把数学知识应用于编程之中,算法会完美。/**************************************************************************************************************************原创 2013-07-19 15:47:25 · 1349 阅读 · 0 评论 -
验证任意一个大于4并且小于500的偶数都可以拆分成两个素数之和
以下代码用于验证 大于 4 小于 500的一个偶数可以拆分成两个素数之和。 #pragma onceclass CJudegeprime{public: CJudegeprime(void); ~CJudegeprime(void);private: bool isprime(int m); int getallprime100(int container原创 2013-07-03 15:50:42 · 2652 阅读 · 0 评论 -
找出数组中出现奇数次的元素
不知道什么时候能用到这个算法,权当练习,其实也是应用数学基础知识的算法。 /**********************************************************************************************************************2.找出数组中出现奇数次的元素问题描述:现在有一个整数数组arr,其中的原创 2013-07-19 16:05:37 · 2612 阅读 · 0 评论 -
电话号码的快速查找
在一个嵌入式项目中,要存储100万条电话号码,同时电话号码的长度最长为11位,为了提高查找的速度,笔者采用11叉树的方式进行存储电话号码,并且支持电话号码的包含关系,所谓包含关系,即要支持1234, 12345这种包含关系。 #pragma once#include #include using namespace std;#define MAX_WAY原创 2013-06-21 15:51:21 · 1617 阅读 · 0 评论 -
实现几个字符串常用函数
实现几个字符串常用函数,练习一下写代码。经常谢谢代码,使自己不要忘了如何写代码。字符比较函数字符串赋值函数求字符串长度字符串那倒置字符串比较字符串连接 // string.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include原创 2013-07-10 12:31:16 · 1222 阅读 · 0 评论 -
一个整形数,如何把某位设置为 0 或者 1
原理部分以单字节数为例,代码部分实现了单字节,双字节,四字节的算法。一个8位(单字节)长度的数某位要设置为0:要把一个8位(单字节)长度的数某一位设置0, 需要把该数和该位为0,但其他各位都为1的数进行与运算。举例一: 运算11111111And原创 2013-06-20 11:09:40 · 2976 阅读 · 0 评论 -
归并排序
在网上看到一个两路归并排序的题目,闲着无聊,就把这个算法是实现了一下。定义:归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的。然后再把有序子序列合并为整体有序序列。#pragma onceclass Cbind{public: Cbind(void); virtual ~Cbind(原创 2013-06-15 12:04:56 · 890 阅读 · 0 评论 -
python 的Dict
python dict原创 2015-10-21 15:01:30 · 606 阅读 · 0 评论