- 博客(26)
- 收藏
- 关注
原创 01 常量的引用
//int &ref = 10; 引用了不合法的内存,不可以 const int &reff = 10; 加入const后编译器处理方式为: int tmp = 10; const int &ref = tmp; int *p = (int*)&ref; *p = 1000; 合法内存,可以修改常量引用使用场景 用来修饰形参 void ShowValue(const int &val) { //val++; 报错,不能改 c.
2021-01-23 11:32:34 146
原创 01 参数三种传递方式
值传递 地址传递 引用传递注意:1、不要返回局部变量的引用2、如果函数返回值是引用,那么函数的调用可以作为引用3、不能有NULL引用,必须确保引用是和一块合法的存储单元关联4、引用必须初始化 int a = 10; int& aRef = a; 编译器自动转换为 int* const aRef = &a; 这也能说明为什么必须初始化 aRef = 20; 内部发现Aref是引用,自动帮我们转换为 *aRef = 20;...
2021-01-23 11:03:10 150
原创 01 引用的基本语法及注意事项
引用 就是起别名1、引用基本语法 Type &别名 = 原名void test01(){ int a = 10; int &b = a; b = 20;} 输出结果 a = b = 202、引用必须初始化void test 02(){ int &a; 错误,没有初始化 一旦初始化后不能修改,B是A的别名,则B不能是C的别名。}3、对数组建立引用void test 03(){ int arr[10]; for (int i = 0;i<1
2021-01-23 10:34:32 188
原创 01 尽量以const代替#define
例:#define MAX 1024;定义的宏MAX从未被编译器看到过,因为在预处理阶段,所有的MAX已经被替换为了1024.区别:1、const有类型,可以进行编译器类型安全检查,#define无类型不可进行类型检查2、const有作用域。#define默认定义到文件尾,也可用#undef A卸载宏常量...
2021-01-23 08:46:18 132
原创 01const分配内存情况
1、对const变量取地址,会分配临时内存。(对临时内存的修改不影响符号表)2、声明时加了extern,编译器也会分配内存(可通过地址修改值)3、用普通变量初始化const变量,也会分配内存4、自定义数据类型(struct)加const也会分配内存...
2021-01-23 08:23:34 267
原创 01C++对C语言的增强
1、全局变量检测增强int a;int a = 10;C通过。C++失败(重定义)。2、函数检测增强,参数类型增强,返回值检测增强,函数调用参数检测增强3、类型转换检测增强4、struct优化C++使用时可以不加struct关键字5、bool类型增强C语言没有bool。C++有bool,只有true或false6、三目运算符增强a > b ? a : b = 100;C不行,C返回的是值。C++返回的是变量,可以作为左值。...
2021-01-22 22:17:14 75
原创 01using声明和using编译指令
using声明:using A; 运行时生效,使用变量就近原则using编译指令:using namespace A; 编译时生效,这句话不管放在哪里就近原则无效
2021-01-22 21:43:25 152
原创 01命名空间namespace的使用
1、命名空间下可以放函数、变量、结构体、类namespace A{ void func(); int m_a; struct Person{}; class Animal;}2、命名空间必须定义在全局作用域下3、命名空间可以嵌套命名空间namespace A{ namespace B { int m_A = 10; }}4、命名空间是开放的,可以随时在原先的命名空间添加内容例:以下两个A空间自动合并,而不会覆盖namespace A{ namespace B
2021-01-22 21:22:00 183
原创 双冒号作用域运算符
#define _CRT_SECURE_NO_WARNINGS#includeusing namespace std;int atk = 200;void test01(){int atk = 100;cout << “攻击力:” << atk << endl;cout << “攻击力:” << ::atk << endl; //双冒号调用全局}int main(){test01();system(“pause”)
2021-01-21 12:04:01 156
原创 VS中Dubug和Release的详细区别
Debug 和 Release 并没有本质的区别,他们只是VC预定义提供的两组编译选项的集合,编译器只是按照预定的选项行动。如果我们愿意,我们完全可以把Debug和Release的行为完全颠倒过来。当然也可以提供其他的模式,例如自己定义一组编译选项,然后命名为MY_ABC等。习惯上,我们仍然更愿意使用VC已经定义好的名称。CONCLUSION:Debug和Release只是两个编译的选项而已,是...
2020-03-20 11:33:45 201
原创 PAT A1102. Invert a Binary Tree (25) [树的遍历]
The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.Now it’s your turn to pro...
2020-01-16 09:36:33 138
原创 PAT A1099. Build A Binary Search Tree (30) [⼆叉查找树BST]
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right subt...
2020-01-16 09:07:16 168
原创 PAT A1094. The Largest Generation (25) [BFS, DFS,树的遍历]
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong tothe same generation. Your task is to find the generation with the largest population.Input S...
2020-01-16 08:24:41 151
原创 PAT A1090. Highest Price in Supply Chain (25) [树的遍历]
A supply chain is a network of retailers(零售商) , distributors(经销商) , and suppliers(供应商) –everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on t...
2020-01-16 07:47:13 187
原创 PAT A1086. Tree Traversals Again (25) [树的遍历]
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...
2020-01-15 20:17:52 129
原创 【笔记】已知先序、中序,构建二叉树
给定二叉树的先序遍历序列 和中序遍历序列,构建二叉树:原理:代码:node* create(int preL,int preR,int inL,int inR){ if(preL > preR){ return NULL; } node* root = new node; root->data = pre[preL]; int k; for(k = in...
2020-01-14 20:47:39 246
原创 PAT A1079. Total Sales of Supply Chain (25) [DFS, BFS,树的遍历]
A supply chain is a network of retailers(零售商) , distributors(经销商) , and suppliers(供应商) –everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on t...
2020-01-05 17:56:26 104
原创 PAT A1066. Root of AVL Tree (25) [平衡⼆叉树(AVL树) ]
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees ofany node difer by at most one; if at any time they difer by more than one, rebalancing is d...
2020-01-05 17:21:18 106
原创 PAT A1064. Complete Binary Search Tree (30) [⼆叉查找树BST]
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The lef subtree of a node contains only nodes with keys less than the node’s key.The right subtr...
2020-01-05 17:04:15 122 1
原创 PAT A1057. Stack (30) [树状数组]
Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out(LIFO). The basic operations include Push (inserting an element onto the top position) and Po...
2020-01-03 20:26:18 107
原创 PAT A1053. Path of Equal Weight (30) [树的遍历]
Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of apath from R to L is defined to be the sum of the weights of all the nodes along the path from R to...
2020-01-03 17:44:14 97
原创 PAT A1043. Is It a Binary Search Tree (25) [⼆叉查找树BST]
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The lef subtree of a node contains only nodes with keys less than the node’s key.The right subtr...
2019-12-31 17:03:33 134
原创 PAT A1020. Tree Traversals (25) [⼆叉树的遍历,后序中序转层序]
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inordertraversal sequences, you are supposed to output the level order traversal sequence of the cor...
2019-12-30 20:23:19 155
原创 PAT A1004 (30) [BFS, DFS,树的层序遍历]
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members whohave no child.InputEach input file contains one test case. Each case starts with a line cont...
2019-12-30 19:02:08 144
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人