小程序杂谈
文章平均质量分 68
linyingzhan
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
链式队列基本功能的简单实现
#include #include #include using namespace std;typedef struct list{int data;struct list *next;}node;typedef struct listQueue{node *front;node *rear;}queue;queue *createQueue(){queue原创 2012-12-06 14:59:27 · 297 阅读 · 0 评论 -
链式栈基本功能的简单实现
#include #include using namespace std;typedef struct list{ int data; struct list *next;}node;typedef struct listStack{ node *top; node *bottom;}stack;stack原创 2012-12-06 14:59:34 · 303 阅读 · 0 评论 -
递归分治实现比赛日程安排(仅对2…
本来是很简单的一个东西,根本没有必要写下来,不过,鉴于是第一次完全使用Ubuntu下面的基础工具(vim、makefile、g++)实现和调试的,所以,贴点膏药: test.cpp:#include using namespace std;#define MaxLength 1000void Table(int **A, int start, int end);void Mer原创 2012-12-06 14:59:06 · 443 阅读 · 0 评论 -
单链表基本操作的简单实现
#include using namespace std;typedef struct list{int data;struct list *next;}node;node *createList(){node *head, *p;p = (node *)malloc(sizeof(node));head = p;int x;while(1){cout<<"Inp原创 2012-12-06 14:59:20 · 283 阅读 · 0 评论 -
双链表一些基本功能的简单实现
#include #include #include using namespace std;typedef struct doubleList{int data;struct doubleList *left;struct doubleList *right;}node;node *create(){node *head, *p, *q;head = (node *原创 2012-12-06 14:59:23 · 274 阅读 · 0 评论 -
约瑟夫问题的简单实现过程
#include #include #include using namespace std;typedef struct circleList{int data;struct circleList *next;}node;node *createList(int n){node *head;node *p;int i;head = (node *)malloc(s原创 2012-12-06 14:59:25 · 324 阅读 · 0 评论 -
快速排序版本一
1 #include 2 #include 3 #include 4 using namespacestd; 5 6 void improveqsort(int *list, int m, intn) 7 { 8 int k, t, i,j; 9 if(m <n) 10 { 11原创 2012-12-06 14:59:36 · 231 阅读 · 0 评论 -
快速排序版本二
1 #include 2 #include 3 #include 4 using namespace std; 5 6 int Partition(int *a, int m, intn); 7 8 void QuickSort(int *a, int low, inthigh) 9 { 10 int pivot; 1原创 2012-12-06 14:59:39 · 275 阅读 · 0 评论 -
字符串中相同的且长度最长的子串
#include #include using namespace std;int main(){ int i, j; string str, tep; cout<<"input astring:" cin>>str; for(i = str.length() - 1; i > 1;i--)原创 2012-12-06 14:59:50 · 292 阅读 · 0 评论 -
排序算法:实现,平均复杂度,最好…
1:冒泡算法 1.1 实现void bubbleSort(int *a, int n){ int i; int j; int flag; for(i = 0; i { flag = 0; for(j = 0; j <n - i - 1;原创 2012-12-06 15:01:14 · 749 阅读 · 0 评论 -
计算下一秒是什么时刻
#include #include using namespace std;void nextSecond(int &year, int&month, int &day, int&hour, int &min, int&second);int main(){int year, month, day, hour, min, second;cout<<"input thet原创 2012-12-06 14:59:17 · 378 阅读 · 0 评论 -
求出一个数字的二进制表达中'1'的…
#include using namespace std;int main(){ int count = 0; int value = 8888; while(value) { count++; value = value & (value -1); } cout return 0;}原创 2012-12-06 14:59:15 · 538 阅读 · 0 评论 -
shell排序
#include using namespace std;void sort(int *a, int left, int right){ int i, j, temp; int gap = right - left + 1; do { gap = (gap / 3) + 1;原创 2012-12-06 14:59:45 · 200 阅读 · 0 评论 -
位运算实现加法的一个简单例子
一个笔试题目,测试了一下,没有错,不过性能不用测试就知道差非常远了~最朴素的想法,用异或操作实现不进位相加,用并操作实现进位标志检测,若有,则左移(进位),继续该过程直到没有进位出现,则异或的结果为最终结果#include#includeint bitAdd(int a, int b){int and;int xor1, xor2;and = a & b;xor1 = a原创 2012-12-06 15:01:07 · 434 阅读 · 0 评论 -
0-1背包问题简单实例(动态规划求…
适用动态规划对0-1背包问题进行了简单的描述,容易看,也可以直接用bag1.cpp:#include using namespace std;void Knapsack(int *v, int *w, int c, int n, int **m);int main(){//0-1 bag problem, using dynamic programmingint c;/原创 2012-12-06 14:59:08 · 624 阅读 · 0 评论 -
0-1背包问题简单实例(回溯法求解…
使用了不太需要的模板来写,而且,因为没有能够找到能在ISO标准下的g++中实现friend函数的方法,结果只能很无奈地全部public了,叹一个~bag2.cpp#include using namespace std;class Object;template <class Typew, classTypep>Typep Knapsack(Typep *p, Typew原创 2012-12-06 14:59:10 · 833 阅读 · 0 评论 -
冒泡排序
#include using namespace std;void sort(int *, int );void swap(int &, int&); int main(){ int *a = new int[10]; int i; cout<<"input 10number:" for(i = 0; i原创 2012-12-06 14:59:41 · 247 阅读 · 0 评论 -
字符串中连续出现次数最多的字串
#include #include #include using namespace std;pair fun(conststring &str){ vectorsubstrs; int maxcount = 1, count = 1; string substr; int i, len = str.length();原创 2012-12-06 14:59:47 · 332 阅读 · 0 评论 -
设计模式
1:Bridge 模式蜡笔与毛笔的区别:蜡笔:只能定义36个单独的对象来实现所有的粗细与颜色毛笔:只需定义3个粗细的毛笔+12种颜料即可实现所有的粗细与颜色模式特点:将继承关系转换为组合关系,降低系统间的耦合,减少代码量。2:单键模式模式特点:a:只能有一个实例b:必须自己创建自己的唯一实例c:必须给所有其他对象提供这一实例3:观察者模式教工收发大米问题:两种不合适的情况:原创 2012-12-06 14:59:53 · 235 阅读 · 0 评论 -
过半数ID查找
//通过一对对删除不同的数来找出超过一半的数究竟是哪一个#include using namespace std;int Find(int [], int);int main(){int a[200];for(int i = 0; i for(int j = 0; j a[i * 10 + j] = j;for(int i = 100; i a[i] = 1;cout原创 2012-12-06 14:59:55 · 265 阅读 · 0 评论 -
快速排序(整型版本)
#includeusing namespace std;void quickSort(int [], int , int);int partition(int [], int , int);void Swap(int &, int &); int main(){ int i; int a[10]; for(i = 0; i { a[i] = 10 - i; } q原创 2012-12-06 14:59:12 · 270 阅读 · 0 评论 -
TCP/IP 协议基本知识笔记
1:TCP/IP 分层 1.1 链路层:设备驱动程序,接口卡 1.2网络层:IP,ICMP,IGMP 1.3 运输层:TCP,UDP 1.4应用层:Telnet,FTP,e-mail等2:TCP/IP 封装 2.1 TCP报文(TCPsegment):TCP传给IP的数据单元 2.2 IP数据报(IPdatagram):IP传给网络接口层的数据单元原创 2012-12-06 15:01:16 · 350 阅读 · 0 评论
分享