- 博客(20)
- 资源 (22)
- 问答 (2)
- 收藏
- 关注
原创 智能指针的简单实现
#include <iostream>using namespace std;class A {public: A(int a, int b) { x = a; y = b; }; int x; int y; void test() { cout << "hello test!" << endl; };};template<typename T>.
2021-11-07 19:34:01
203
原创 swap 漏洞
今天写快排,发现了一个漏洞,使用加减和异或实现的 swap 需要注意传入的是否是同一个个数。否则 swap 后数值会归零!!!!!!!!!!#include <cstdio>using namespace std;void swap(int &x, int &y) { if(x == y) return ; x = x + y; y = x - y; x = x - y;}void printArray(int a[], int
2021-09-24 17:10:24
229
原创 扫描线求矩形面积
struct scanLine { int x1; int x2; int y; int cover; scanLine() {}; scanLine(int _x1, int _x2, int _y, int _cover) : x1(_x1), x2(_x2), y(_y), cover(_cover) {}; bool operator<(const scanLine & l) { return y < l.
2021-08-15 11:03:27
248
原创 手写 string 类
// 头文件#ifndef MYSTRING_H#define MYSTRING_H#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class myString{ friend ostream & operator<<(ostream & out, myString &) ; friend istre.
2021-08-15 10:23:45
632
原创 手写红黑树
手写代码遇到了一些问题,先贴代码,以后慢慢讲。#include <iostream>#include <queue>using namespace std;#define RED 0 // 红色节点#define BLACK 1 // 黑色节点typedef int Key;typedef int Data;typedef struct _node { int color; Key key; Data data; ...
2021-07-28 16:04:52
115
原创 单链表排序(快排、归并)
// 快排 交换值void quickSort(ListNode * s, ListNode * t) { if(s == t || s->next == t) return ; ListNode * mid = partation(s,t); quickSort(s,mid); quickSort(mid->next,t);}LinkNode * partation(ListNode * s, ListNode * t) { if(s == t.
2021-06-21 16:37:08
116
原创 go 如何正确关闭channel
go 语言并发,使用channel时,如何正确的关闭 channel 是个值得注意的问题,尤其是在多个 sender 和 多个 receiver 的情况下。 这里我用程序模拟了一条生产线,生产线上有4种类型的 worker,它们分别负责处理任务的一部分,接力完成任务,每个 worker 间的管道都带有缓存。当任务不再产生时,需要依次关闭 channel。这里考虑对 channel 附加计数器,标识 channel 上发送者的数目,当计数器为1时,关闭 channel。为预防多个 sende...
2020-09-23 16:10:52
2352
原创 寻找平面上最近的点对
#include <stdio.h>#include <stdlib.h>#include <time.h>#define MAX_DIS 65536struct point{ int x; int y;};char result[64]="\0";int cmp_x(const void * p1, const void ...
2019-10-15 15:20:56
331
原创 K路归并的一个简单实现
#include <stdio.h>#include <stdlib.h>#include <time.h>struct NODE{ int data; //数据 int mark; //标记->来自哪一个数组} ;int node_num;void get_random_array(int *a, int l){...
2019-10-06 09:11:45
299
原创 KMP字符串匹配
#include <stdio.h>#include <stdlib.h>#define MAX_SIZE 1024//原版的next数组void get_next(char *s,int next[]){ int l=strlen(s); int j=0; int k=-1; next[0]=-1; while(j&l...
2019-03-09 09:39:18
161
原创 字符串全排列 递归与非递归
#include <stdio.h>#include <stdlib.h>void swap(char * x,char * y){ char tmp=*x; *x=*y; *y=tmp;}//递归算法void permutation(char *s,int b,int e){ if(b==e) { ...
2019-03-08 10:40:23
511
1
原创 各种排序
#include <stdio.h>#include <stdlib.h>#include <time.h>int create_array(int a[]){ int i; srand(time(NULL)); int n=rand()%64; for(i=0;i<n;i++) { a[...
2019-03-07 09:33:08
163
原创 最短路径问题
#include <stdio.h>#include <stdlib.h>#define MAX_SIZE 128#define INF 65536typedef int DATA;typedef struct{ int no; //编号 //DATA data; //数据} Vertex;typedef struct{ Ver...
2019-03-01 18:13:29
541
原创 链表 两个数相加
#include <stdio.h>#include <stdlib.h>struct ListNode{ int val; struct ListNode *next;};struct ListNode * createList(int a[],int length){ printf("create list\n"); in...
2019-02-23 15:42:23
408
原创 scrapy学习笔记
Scrapy是一个爬虫框架,它包含engine、scheduler、downloader、spider和pipeline。它们的关系如图所示Spider就是配置爬虫、解析网页的组件。可以用Selector内置的xpath、css、re来解析页面通过extract()函数返回unicode字符串列表,extract_first()返回unicode字符串。
2017-12-25 09:38:12
250
原创 单链表上归并排序的实现
#include <stdlib.h>struct LinkList{ int data; struct LinkList * next;};void CreateLinkList(struct LinkList * );void DisplayLinkList(struct LinkList *);void DestoryLinkList(...
2016-11-09 18:10:24
683
原创 判断一个字符串是否是IP地址
#include int main(){ char str[] = "111.111.111.21"; char str2[] = "a.111.111.111"; char str3[] = "11.1.1.1.d"; printf("%d\n",isIP(str)); printf("%d\n",isIP(str2)); printf("%d
2016-11-01 22:36:17
3441
原创 指针和数组的一些问题
数组与指针本来就是两种不同的类型,它们有很多不同之处,不能混淆。但是在实际运用中,有时却可以看作相同的。具体它们有哪里联系呢?先写一点内容,以后再完善。 数组名和指针实际上,数组名就是一个地址,它是一个不可修改的左值。出于对效率的考虑,传递给函数的数组参数会转化为指针。这个指针指向该数组第一个元素。注意,首先,该指针的地址并不等同于数组名的地址;其次,该规则并不是递归的。例如,数组的数
2016-10-05 16:34:06
349
原创 操作系统:用二值信号量和一些机器指令实现计数信号量
Show how counting semaphores (i.e., semaphores that can hold an arbitrary value) can be implemented using only binary semaphores and ordinary machine instructions.译: 如何用二值信号量和一些机器指令实现计数信号量。
2015-11-03 22:59:06
2756
原创 c 语言:一个链表的实现
#include #include typedef int ElementType;typedef int BOOL;#define TRUE 1#define FALSE 0inline BOOL compare(int a,int b,BOOL flag){ if(( a > b && !flag)||( a < b && flag)) return TRUE; else return FAL
2015-10-23 17:06:41
338
PARZEN窗和K近邻算法的python实现
2019-11-23
文件加密程序,可自定义秘钥
2019-11-23
算法导论(第三版 中文 带页签)
2018-05-31
Netty权威指南 第2版 带书签目录 完整版.pdf
2018-05-31
Introduction for deep learning techniques and its applications.pdf
2018-05-31
数据结构习题
2018-05-29
经典算法讲义-中科大
2018-05-29
pyspider 项目如何retry failed的网页
2017-10-23
python使用urllib2 批量下载文件,遇到校验怎么办?
2017-09-26
TA创建的收藏夹 TA关注的收藏夹
TA关注的人