- 博客(15)
- 收藏
- 关注
原创 将博客搬至优快云
此博客即将废弃,所有内容将迁往优快云以下是新地址http://blog.youkuaiyun.com/woshiaotian 博客有了新站http://vearne.cc/
2012-12-22 21:35:59
127
原创 linux线程同步--条件变量练习(2)
注意:消息是由主线程产生的,而消息这时候在堆中,两个线程通过全局变量获取访问消息。#include <pthread.h>#include <stdlib.h>#include <stdio.h>struct msg { int data; struct msg *m_next; /* ... more stuff her...
2012-08-07 18:00:03
134
原创 linux线程同步--条件变量练习(1)
注意:消息是由主线程产生的,而消息这时候在栈中,两个线程通过全局变量获取访问消息。Unix环境高级编程P288进程的所有信息对该进程的所有线程都是共享的,包括可执行的程序文本、程序的全局变量和堆内存、栈以及文件描述符。 #include <pthread.h>#include <stdio.h>struct msg { int data; ...
2012-08-06 23:27:24
148
原创 使用linux函数模拟HTTP 请求过程
非常好的参考资料1.HTTP 协议资料http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.22.使用telnet模拟浏览器访问网页http://pcwanli.blog.163.com/blog/static/4531561120091115105240732/ #include "apue.h"...
2012-08-01 21:50:36
430
原创 重复删除指针
#include <iostream>using namespace std;class Base{public: void f(){ cout<<"base"<<endl; }private: int a;};int main(){ Base* b = new Base; delete b; dele...
2012-07-27 22:10:14
258
原创 继承关系中的早绑定
#include <iostream>using namespace std;class Base{public: void f(){ cout<<"base"<<endl; }};class Derived:public Base{public: void f(){ cout<<"derived...
2012-07-27 09:00:48
130
原创 关于僵尸进程的练习。
请参考linux c一站式学习,此节内容http://learn.akae.cn/media/ch30s03.html#id2867242可以设置父进程忽略SIGCHLD信号,或者在SIGCHLD信号的处理函数中调用wait函数,即可获取子进程的退出状态,且销毁僵尸进程。1)调用wait函数 #include <unistd.h>#include <std...
2012-07-19 10:17:40
98
原创 has virtual functions but non-virtual destructor
#include <iostream>using namespace std;class based{public: based(){ } ~based(){ cout<<"flag 1"<<endl; } virtual void f(){ cout<<"ok1"<<endl;
2012-07-14 13:36:47
7050
原创 二叉树的中序遍历
#include <iostream>#include <stack>using namespace std;struct node{int data;struct node* lchild;struct node* rchild;};typedef struct node Node;void inOrderTraverse(Nod...
2012-07-13 10:04:51
126
原创 两个有序数组求中位数的O(logn)算法
#include <iostream>using namespace std;int get_median(int a[],int begin1,int end1,int b[],int begin2,int end2,int k){ if(begin1>end1){ //在数组A中无法找到 return get_median(b,begin2,end2,...
2012-07-13 00:16:55
637
原创 智能指针的简易实现
#include <iostream>using namespace std;class smart_count{private: int use_count;public: smart_count(int c=0):use_count(c){ } ~smart_count(){} int addref(){ return ++us...
2012-07-12 16:26:52
102
原创 C++中把多维数组传递给函数可使用模版的办法
#include <iostream>using namespace std;template<int m,int n>void print(int a[m][n]){ for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cout<<a[i][j]<<" "; ...
2012-07-11 23:30:53
186
原创 图的广度深度遍历(邻接矩阵)
#include <iostream>#include <queue>#include <algorithm>#include <stack>using namespace std;int a[5][5]={{0,1,0,1,0},{1,0,1,0,1},{0,1,0,1,1},{1,0,1,0,0},{1,0,1,0,0}...
2012-07-11 23:25:41
367
原创 堆排序代码实现
void heap_adjust(int a[],int i,int size){ int temp; int j = i*2 +1; if(i<=size/2-1){ //保证其为非叶子节点----这里请注意 if(j+1<size&&a[j]<a[j+1]){ //找出子节点中值最大的 j++; } if(a...
2012-07-01 23:37:42
83
java中两种有趣的匿名类实现
java中的匿名类除了还有两种有趣的用法 /** * TODO Comment of AnonymousTest * * @author aotian.zhuw */class EntryInterface { public void print() { System.out.println("hello world"); ...
2011-10-30 14:52:09
164
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人