- 博客(20)
- 资源 (1)
- 收藏
- 关注
原创 c++移动构造,移动赋值
class A{ public: A(int i = 0){ _i = new int(i); cout<<"A()"<<endl; } ~A(){ if(_i != nullptr){ delete _i; _i = nullptr; } cout<<"~A()"<<endl; } A(A c
2020-08-11 16:18:25
274
原创 智能指针shared_ptr自实现
template <typename T> class myshared_ptr{ public: myshared_ptr(T* ptr = nullptr):_ptr(ptr){ count = new int(0); if(ptr != nullptr){ *count = 1; } cout<<"myshared_ptr(T* ptr = nullptr)"<<endl
2020-08-11 16:14:54
214
原创 c++堆排序
#include <iostream> using namespace std; #include <string.h> #include <vector> void maxheap(vector<int>& ans,int i,int n){ int l = i * 2 + 1; int r = i * 2 + 2; int max = i; if(l < n && ans[l] > an
2020-07-12 11:27:30
198
原创 c++归并排序
#include <iostream> using namespace std; #include <string.h> #include <vector> void merge(int low,int mid,int high,vector<int>& ans,vector<int>& tem){ int l = low; int h = mid + 1; int k = low; while(l
2020-07-12 10:54:26
133
原创 c/c++二叉树的前中后遍历
#include <stdio.h> #include <stdlib.h> typedef struct _tree { char data; struct _tree *left; struct _tree *right; }tree; typedef struct _stack { tree **data; int top; ...
2020-04-06 20:16:13
174
原创 c/c++栈的链式存储
.h #ifndef MYSTACK_H #define MYSTACK_H typedef struct _node { char data; struct _node *next; }Node; class mystack { public: mystack(); int isempty(); void push(char data); ch...
2020-04-05 19:57:48
200
原创 C++栈的实现
.h #ifndef STATCK_H #define STATCK_H class statck { public: statck(int len); ~statck(); int isempty(); int isfull(); void push(char data); char pop(); private: int len; ...
2020-04-05 19:53:16
139
原创 c语言队列的实现
线性队列 #include <stdio.h> #include <stdlib.h> typedef struct _node { char *space; int len; int front; int rear; }queue; void init(queue* q,int len) { q->len = len; ...
2020-04-05 19:49:45
155
原创 C语言单向链表
头文件 #ifndef MYLIST_H #define MYLIST_H #endif // MYLIST_H typedef struct _Node { int data; struct _Node *next; }Node; Node *creatList(); void traverList(Node *head); int strlenList(Node *head...
2019-10-11 22:14:49
151
原创 逆置字符串保存
/*将逆置的字符串保存*/ void strReverse(char *buf,char *bufSave) { if(*buf) { strReverse(buf+1,bufSave+1); strncat(bufSave,buf,1); } } int main(void) { char buf[100] = "china";...
2019-09-02 20:38:12
248
原创 字符串去除空格,解决文件登陆问题
#include <stdio.h> #include <stdlib.h> /*去除左边空格*/ void trimLeftSpace(char *p) { if(*p != ' ') return; char *str = p; while(*str == ' ') str++; while(*p++ = ...
2019-09-02 20:17:08
144
原创 strtok实现原理
#include <stdio.h> #include <string.h> #include <stdlib.h> static char *olds; static char *save_ptr; char *strtok1(char *s, const char *delim) { char *token; if (s == NULL)...
2019-08-26 20:48:10
299
原创 strchr,strstr自实现
#include <stdio.h> #include <stdlib.h> int strchrcount(char *src,char ch) { int count = 0; while(*src) { if(*src == ch) count++; src++; } r...
2019-08-25 09:04:38
194
原创 自实现strlen,strcpy,strcat,strcmp
strlen int mystrlen(const char *src) { int len = 0; while(*src++) len++; return len; } strcpy char *mystrcpy(char *dest,const char *src) { char *d = dest; while(*dest++ = ...
2019-08-24 09:14:46
160
原创 C语言将文件写入到堆内存中
我是黑体字 我是微软雅黑 我是华文彩云 color=#0099ff size=72 face=“黑体” color=#00ffff color=gray #include <string.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char b...
2019-08-23 21:09:20
705
原创 C语言数组的几种排序方法
#include <stdio.h> #include <time.h> /*快速排序法*/ void quickSort(int *p,int low,int high) { if(low < high) { int temp = p[low]; int l = low; int h = high; ...
2019-08-23 15:46:38
2024
原创 C语言快速排序
#include <stdio.h> #include <time.h> void quickSort(int *p,int low,int high) { if(low < high) { int tem = p[low]; int l = low; int h = high; whil...
2019-08-22 10:56:23
227
原创 C语言双向链表
包含双向链表的创建,插入,遍历,查找,排序,删除,销毁。 #include <stdio.h> typedef struct node { int data; struct node *next; struct node *pre; }Node; Node *creatList() { Node *head = (Node*)malloc(sizeo...
2019-05-27 15:15:07
291
2
原创 strstr的使用
strstr以及自实现strstr 函数介绍 char *str(char *string,char *str) 返回第一次在字符串string中查到str的地址,如果查不到则返回NULL。 /*统计一个字符串在另外一个字符串中出现的次数*/ int calStrCountOfStr(char *string,char *str) { int count = 0; int len ...
2019-05-16 15:36:03
438
原创 strchr函数的实现与对比
strchr strchr 函数介绍 函数声明 char strchr(char str,char ch),包含在头文件string.h中。 函数功能:返回字符串str中首次出现字符ch的指针,没有 则返回NULL。 #include<stdio.h> #include <string.h> /*统计一个字符在字符串内出现的次数*/ int calcCharCountOfS...
2019-05-16 10:27:38
305
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅