
c、c++
mingxiaoshan
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
智能指针的简单实现
#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 · 218 阅读 · 0 评论 -
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 · 250 阅读 · 0 评论 -
扫描线求矩形面积
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 · 269 阅读 · 0 评论 -
手写 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 · 647 阅读 · 0 评论 -
手写红黑树
手写代码遇到了一些问题,先贴代码,以后慢慢讲。 #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 · 130 阅读 · 0 评论 -
单链表排序(快排、归并)
// 快排 交换值 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 · 130 阅读 · 0 评论 -
寻找平面上最近的点对
#include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX_DIS 65536 struct point{ int x; int y; }; char result[64]="\0"; int cmp_x(const void * p1, const void ...原创 2019-10-15 15:20:56 · 344 阅读 · 0 评论 -
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 · 322 阅读 · 0 评论 -
字符串全排列 递归与非递归
#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 · 527 阅读 · 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 · 177 阅读 · 0 评论 -
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 · 177 阅读 · 0 评论 -
最短路径问题
#include <stdio.h> #include <stdlib.h> #define MAX_SIZE 128 #define INF 65536 typedef int DATA; typedef struct { int no; //编号 //DATA data; //数据 } Vertex; typedef struct { Ver...原创 2019-03-01 18:13:29 · 560 阅读 · 0 评论 -
链表 两个数相加
#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 · 428 阅读 · 0 评论 -
判断一个字符串是否是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 · 3468 阅读 · 0 评论 -
单链表上归并排序的实现
#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 · 700 阅读 · 0 评论 -
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 · 347 阅读 · 0 评论 -
指针和数组的一些问题
数组与指针本来就是两种不同的类型,它们有很多不同之处,不能混淆。但是在实际运用中,有时却可以看作相同的。具体它们有哪里联系呢?先写一点内容,以后再完善。 数组名和指针 实际上,数组名就是一个地址,它是一个不可修改的左值。出于对效率的考虑,传递给函数的数组参数会转化为指针。这个指针指向该数组第一个元素。注意,首先,该指针的地址并不等同于数组名的地址;其次,该规则并不是递归的。例如,数组的数原创 2016-10-05 16:34:06 · 366 阅读 · 0 评论