- 博客(29)
- 收藏
- 关注
原创 基于tcp的socket编程。
一。server端:#include#includeusing namespace std;#pragma comment(lib,"ws2_32.lib")void main(){WORD wVersionRequested;WSADATA wsaData;int err;wVersionRequested = MAKEWORD( 2,
2015-10-11 18:04:31 310
原创 auto_ptr,weak_ptr个人理解
1.auto_ptr存在很大的缺陷,因为auto_ptr的拷贝构造函数中会把原来的指针赋值为空,在对原来的进行引用就是非法操作。例子:auto_ptr p1(p);auto_ptr p2(p);//非法,因为p被f赋值为空。2.shard_ptr,在智能指针中已经很完美了,但是美中不足的地方,便是在与解决循环引用的问题。例如:class A{
2015-10-10 23:17:36 412
原创 两个栈实现一个顺序栈
#include #include usingnamespacestd;class STACK{public: void Push(int val) {stackint> temp; temp.push(val); while (st.empty() == false) {if (st.top() >
2015-10-10 23:03:47 550
原创 两个栈实现队列(完整理解)
自己总结了两个栈实现队列的三种方法:方法1:入队时候:将元素压入栈s1.出队时候:将s1的所有元素逐个(出栈并入栈到)s2中;将s1的栈顶元素弹出作为出队列元素。之后再将s2的所有元素(出栈并入栈)到s1. 实用范围:一次出队列,一次入队列,交替出现的情况。优化:将s1的元素(出栈并入栈到)s2中,s1的栈底元素不用入栈到深,直接作为出队元素。
2015-10-05 12:12:53 455
原创 二叉树的深度广度遍历
深度优先搜索算法(Depth First Search),是搜索算法的一种。是沿着树的深度遍历树的节点,尽可能深的搜索树的分支。当节点v的所有边都己被探寻过,搜索将回溯到发现节点v的那条边的起始节点。这一过程一直进行到已发现从源节点可达的所有节点为止。如果还存在未被发现的节点,则选择其中一个作为源节点并重复以上过程,整个进程反复进行直到所有节点都被访问为止。如右图所示的
2015-09-17 12:24:55 383
转载 内存对齐规则
首先由一个程序引入话题: 1 //环境:vc6 + windows sp2 2 //程序1 3 #include 4 5 using namespace std; 6 7 struct st1 8 { 9 char a ;10 int b ;11 short c ;12 };13 14 struct st
2015-08-09 21:09:18 232
原创 内存中关于开辟空间,堆,栈,静态区
一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。 2、堆区(heap) — 一般由程序员分配释放 , 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表。 3、全局区(静态区)(static)—,全局变量和静态变量的存
2015-08-09 21:08:24 3253
原创 二叉树的创建及简单操作
#pragma once#include#include#include#includeusing namespace std;typedef int DataType ;struct BinaryNode{DataType _data;BinaryNode *_left;BinaryNode *_right;BinaryNode(DataT
2015-07-16 15:25:46 281
原创 特殊单链表的一些操作
1,建一个有环单链表:#includeusing namespace std;#includestruct Node{int _data;struct Node *next;};typedef Node *PList;Node* CreatNode(int x)//创建节点{Node *tmp
2015-07-15 16:15:09 227
转载 虚函数
//首先让我们来了解类对象的构造顺序。#include using namespace std;class A{public: A(){ cout "A" << endl; } virtual void PrintfA() = 0;};class B {public: B(){ cout "B" << endl; }};class C :virtual
2015-07-15 15:30:15 423
转载 虚函数,虚表
一、虚函数 首先,虚函数的定义为在函数前添加关键字virtual。然后,之所以定义虚函数,是为了实现语言的多态性的特点。 虚函数里面有纯虚函数的玩意。通过直接在虚函数后面添加= 0来实现,举例如下: virtual void (*Fun)() = 0; 应该注意的是,当一个类中出现了至少一个纯虚函数时,这个类就
2015-07-15 14:57:37 498
原创 单链表常见操作
#includeusing namespace std;#includestruct Node{int _data;struct Node *next;};typedef Node *PList;void printfback(PList head)//从后面打印{stack s;Node* begin = head;while
2015-07-15 14:55:26 182
原创 引用计数板的智能指针实现
#includeusing namespace std;templateclass smart_ptr{public:smart_ptr(T *p) {_ptr = p;_pcount = new int(1);}smart_ptr(const smart_ptr &s){_ptr = s._ptr;_pcount = s._pcount;
2015-07-11 15:06:45 240
原创 string类和智能指针(简洁版)和shareptr简洁版代码实现
/*#includeusing namespace std;#includetemplateclass String{public:String(){_str = new char[1];_str[0] = '\0';}String(const char *str){_str = new char[strlen(str) + 1];str
2015-07-11 13:04:48 458
原创 c与c++关键字的用法总结
/*1,关键字的总结register:(1),这个关键字请求编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻址访问,以提高效率。(2),register定义的变量:register int num=10;不能对其取地址。即不能:int *p=&num.const:(1),const修饰变量,以下两种定义形式在本质上是一样的。它的含义是:const修饰的类型为TY
2015-07-08 14:36:02 659 1
原创 }1.字符串替换空格:请实现一个函数,把字符串中的每个空格替换成“%20”。例如输入“we are happy.”,则输出“we%20are%20happy.”。
#include#includevoid repace_black(char *str){char *start = str;int black = 0;int len = strlen(str);int newlen = 0;char *pstr = str + len ;char *newpstr = NULL;while (*str){if (
2015-07-04 10:15:13 656
原创 c语言常用函数实现
/*#includechar* my_strcpy(char *dest,const char *src){char *ret = dest;while (*src){*dest = *src;*dest++;*src++;}*dest = *src;return ret; }void main(){char a[] =
2015-07-03 20:42:38 355
原创 斐波那契shell实现
#!/bin/bashread valarr[0]=1arr[1]=1i=0while [ $i -le $val ]do (( arr[$i+2]=arr[$i+1]+arr[$i] )) ((i++)) done echo ${arr[$val]}
2015-07-03 20:41:28 556
原创 shell实现的进度条
#!/bin/basharr=('|' '/' '-' '\\')function proc(){ local index=0 for((i=0;ido echo -e -n "\033[34m" let ch=index%4 let index++ str="${str}"'*'
2015-07-03 20:14:42 431
转载 不使用+-*/计算两个数的和
#includeint Add( int x, int y) { if( y == 0 ) { return x; } else { return Add( x ^ y, (x & y) } }int main(){printf("%d\n",Add( 2, 3));}
2015-06-30 16:41:01 495
原创 二进制有关问题
有1000瓶液体,⽆⾊⽆味,外表完全⼀样,其中⼀瓶是毒药,有10条警⽝,警⽝喝过毒药后两⼩时后死亡。问,如何在两个⼩时后确定哪瓶是毒药解法:因为有1000瓶液体。10条警犬。分别给这1000瓶液体编号,为(1~10000)用二进制表示:10位就够了。因为2^10=1024给这10只警犬分别编号(1~10)表示这1000瓶液体为:0000 0000 01
2015-06-30 15:03:41 309
原创 c++实现计算机中的文件复制
#includeusing namespace std;#include void main(int argc, char *argv[]){FILE *fpIn = NULL;FILE *fpOut = NULL;if(argc != 3){coutexit(1);}fpIn = fopen(argv[1],"rb");if(fpIn == N
2015-04-27 11:34:13 721
转载 内存泄露工具(用hash表实现)
#include #include #include #include #define DefaultSize 7 using namespace std; struct Node { char *pname;//文件名字 int line;//行号 int size;//大小 long lo
2015-04-21 11:13:18 294
转载 内存泄露检测工具
#include #include using namespace std; struct MemNode { char *pname;//文件名 int line;//文件所在行 int size;//内存泄漏大小 MemNode *link; }; MemNode *node=NULL
2015-04-21 11:10:09 235
转载 运行成功的最新进度条代码
源代码#include "process.h"#include#include#includevoid process(){ int i=1; char buf[_SIZE_]; memset(buf, ' ', sizeof(buf)); buf[0]='['; buf[101]=']'; buf[1
2015-04-07 17:10:38 477
转载 limux下进度条代码
1 建⽴proccess.h代码如下:#ifndef _PROCCESS_#define _PROCCESS_#include #include #include #define _SIZE_ 103void process();#endif2.建⽴proccess.c#include "proccess.h"void process(){i
2015-04-07 15:46:50 291
转载 迷宫代码
#includeusing namespace std;templateclass Stack{public:Stack(){capacity = STACK_SIZE;base = new Type[capacity];top = 0;}~Stack(){delete []base;base = NULL;top = 0;cap
2015-03-12 11:50:57 719
原创 二分法
#includeusing namespace std;int Find(int arr[5],int n,int key){ int low=0,high=n-1; while(low{int mid=(high+low)/2;if(key{ high=mid-1;}else if(key>arr[mid]){
2015-03-08 13:43:51 276
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人