摘要: 1.二叉树遍历 1.1 前序遍历 根、左、右 A B D H E I C F J K G 代码模版 递归 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeN 阅读全文
posted @ 2021-01-27 23:18 _一只土拨鼠 阅读(77) 评论(0) 推荐(0)
摘要: 移位运算 1. 逻辑移位 逻辑移位:移出去的位丢弃,空缺位(vacant bit)用 0 填充。 2. 算术移位 算术移位:移出去的位丢弃,空缺位(vacant bit)用“符号位”来填充。 3. 举例 对于无符号数,左移右移都是逻辑移位 对于有符号数,左移是逻辑移位,右移是算术移位 具体操作 1. 阅读全文
posted @ 2021-01-23 17:38 _一只土拨鼠 阅读(650) 评论(0) 推荐(0)
摘要: 1. 二分查找 C++ STL标准库中提供有 lower_bound()、upper_bound()、equal_range() 以及 binary_search() 这 4 个查找函数,它们的底层实现采用的都是二分查找的方式。 1.1 lower_bound() lower_bound() 函数用 阅读全文
posted @ 2021-01-17 12:24 _一只土拨鼠 阅读(84) 评论(0) 推荐(0)
摘要: 1. 背景 当一个程序被执行时,系统维护一个执行堆栈来存储关于程序中活动函数的信息。执行堆栈中存储的一个重要信息是函数终止时要执行的下一条指令的地址。 在许多C/C++代码中,我们通过写入数组的末尾,可能破坏执行堆栈。这被称为smash the stack。 当函数终止时,控制流将跳转到内存中的随机 阅读全文
posted @ 2021-01-16 12:29 _一只土拨鼠 阅读(92) 评论(0) 推荐(0)
摘要: 1. 内联函数 用法 采取以下措施之一: 在函数声明前加上关键字inline 在函数定义前加上关键字inline 通常的做法是省略原型,将整个定义放在原本应该提供原型的地方 inline double square(double x) { return x*x; } 2. 引用变量 引用是已定义的变 阅读全文
posted @ 2020-12-27 23:22 _一只土拨鼠 阅读(44) 评论(0) 推荐(0)
摘要: 指针 声明和初始化 int* point; // int* 是一种类型,指向int的指针 int higgens = 5; int* pt = &higgens; cout << higgens; // 5 cout << &higgens; // 0012FED4 cout << *pt; // 阅读全文
posted @ 2020-12-26 22:40 _一只土拨鼠 阅读(106) 评论(0) 推荐(0)
摘要: 剑指 offer 58 题目 输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。为简单起见,标点符号和普通字母一样处理。例如输入字符串"I am a student. ",则输出"student. a am I"。 无空格字符构成一个单词。 输入字符串可以在前面或者后面包含多余的空格, 阅读全文
posted @ 2020-12-23 22:58 _一只土拨鼠 阅读(82) 评论(0) 推荐(0)
摘要: 简介 要包含头文件 #include <string> 可以用cin和cout输入输出 可以用数组表示法来访问存储在string对象里的字符串 string str = "apple"; cin >> str; cout << str; cout << str[2]; 使用 拼接 str += "b 阅读全文
posted @ 2020-12-23 17:48 _一只土拨鼠 阅读(42) 评论(0) 推荐(0)
摘要: 谷歌pagerank算法 数据描述 Directed graph (each unordered pair of nodes is saved once): web-Google.txt Webgraph from the Google programming contest, 2002 Nodes 阅读全文
posted @ 2020-12-23 14:17 _一只土拨鼠 阅读(179) 评论(0) 推荐(0)
摘要: 读取csv文件(movie数据集) import pandas as pd df_rating = pd.DataFrame(pd.read_csv('ratings.csv')) for index, row in df_rating.iterrows(): userId = row["userI 阅读全文
posted @ 2020-12-23 14:08 _一只土拨鼠 阅读(111) 评论(0) 推荐(0)