- 博客(13)
- 资源 (4)
- 收藏
- 关注
原创 clang -Xclang -ast-print -fsyntax-only main.cc > main-init.cc
分析C++泛型编程的利器,生成实例化后的代码
2020-11-25 07:12:36 562
原创 C++STL-vector实现 空间配置器
一、没有空间配置器的vector#include <iostream>#include <cstring>using namespace std;template <typename T>class vector {private: T *_first; T *_last; T *_end;public: vector(int size=10) { _first = new T[size]; _end = _first+s
2020-11-22 09:18:56 359 2
原创 带右值引用的拷贝构造函数和运算符重载函数
考虑一个占用堆资源类对象的拷贝构造和赋值运算符重载函数,当我们用一个临时对象去拷贝构造一个新对象或者赋值给一个已经存在的对象时,会出现一下的问题:如string类#include <iostream>#include <cstring>using namespace std;class MyString {private: char *mptr;public: MyString(const char *src = nullptr) { cout <<
2020-11-22 01:54:50 729 1
原创 面试22.栈的压入、弹出
题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如,序列 {1,2,3,4,5} 是某栈的压栈序列,序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列,但 {4,3,5,1,2} 就不可能是该压栈序列的弹出序列。样例1:输入:pushed = [1,2,3,4,5], popped = [4,5,3,2,1]输出:true解释:我们可以按以下顺序执行:push(1), push(2), push(3), push
2020-11-21 23:26:26 205
原创 C++对象的优化--减少不必要的函数调用
测试环境:win10+vs2013初始代码:#include <iostream>using namespace std;class Test {private: int ma;public: Test(int data = 10) :ma(data) { cout << "Test(int)" << endl; } Test(const Test& t) :ma(t.ma) { cout << "Test(const
2020-11-21 22:58:25 554
原创 C++-对象的生存周期
#include <iostream>using namespace std;class A {private: int ma;public: A(int a=20):ma(a) {cout << "A(int)" << endl;} ~A() {cout << "~A()" << endl;} A(const A& t):ma(t.ma) {cout << "A(const A&)" <<
2020-11-21 18:36:48 177
原创 单链表逆置(递归和迭代)
迭代class Solution { public ListNode reverseList(ListNode head) { if (head == null) return head; ListNode a=head, b=head.next; head.next = null; while (b != null) { ListNode c = b.next; b.next = a; a = b; b = c;
2020-11-16 01:31:40 325
原创 递归逆序和正数输出正整数
正序输出#include <bits/stdc++.h>using namespace std;void print(int x) { if (x == 0) return; print(x/10); cout << x%10 << " ";}逆序输出#include <bits/stdc++.h>using namespace std;void reversePrint(int x) { if (x == 0) { retu
2020-11-15 16:24:14 594
原创 BF算法-串匹配算法
串的模式匹配:暴力算法,时间复杂度为O(n)。#include <bits/stdc++.h>using namespace std;// 返回第一次匹配到的位置int bf(char *s, char *t) { int i=0,j=0,k=0; while (i < strlen(s) && j < strlen(t)) { if (s[i] == t[j]) { i ++, j++; } else { j = 0; // 模式串
2020-11-11 10:51:08 160
原创 层序遍历求树的深度
#include <bits/stdc++.h>using namespace std;struct TreeNode { int val; TreeNode *left, *right;};void dfsGetDepth(TreeNode *root, int &x) { if (!root) return; queue<TreeNode*> q; q.push(root); while (!q.empty()) { int
2020-11-09 21:20:30 550 1
LinkedListProblems.pdf
2019-10-29
Effective C++中文第三版高清
2018-08-02
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人