mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
README 改版,使用 summary 收缩目录内容
This commit is contained in:
parent
71605ec3d6
commit
b3e9a1320d
|
@ -2,51 +2,61 @@
|
|||
|
||||
计数排序:统计小于等于该元素值的元素的个数i,于是该元素就放在目标数组的索引i位(i≥0)。
|
||||
|
||||
计数排序基于一个假设,待排序数列的所有数均出现在(0,k)的区间之内,如果k过大则会引起较大的空间复杂度
|
||||
计数排序并非是一种基于比较的排序方法,它直接统计出键值本应该出现的位置
|
||||
时间复杂度为O(n),空间复杂度为O(n+k)
|
||||
计数排序基于一个假设,待排序数列的所有数均为整数,且出现在(0,k)的区间之内。
|
||||
如果 k(待排数组的最大值) 过大则会引起较大的空间复杂度,一般是用来排序 0 到 100 之间的数字的最好的算法,但是它不适合按字母顺序排序人名。
|
||||
计数排序不是比较排序,排序的速度快于任何比较排序算法。
|
||||
时间复杂度为 O(n+k),空间复杂度为 O(n+k)
|
||||
|
||||
算法的步骤如下:
|
||||
|
||||
1. 找出待排序的数组中最大和最小的元素
|
||||
2. 统计数组中每个值为 i 的元素出现的次数,存入数组 C 的第 i 项
|
||||
3. 对所有的计数累加(从 C 中的第一个元素开始,每一项和前一项相加)
|
||||
4. 反向填充目标数组:将每个元素 i 放在新数组的第 C[i] 项,每放一个元素就将 C[i] 减去 1
|
||||
|
||||
*****************/
|
||||
|
||||
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void countSort(vector<int>& vec,vector<int>& objVec)
|
||||
// 计数排序
|
||||
void CountSort(vector<int>& vecRaw, vector<int>& vecObj)
|
||||
{
|
||||
vector<int> range(10,0); //range的下标即键值
|
||||
for(int i=0;i<vec.size();++i)
|
||||
{//统计每个键值出现的次数
|
||||
range[vec[i]]++;
|
||||
}
|
||||
// 确保待排序容器非空
|
||||
if (vecRaw.size() == 0)
|
||||
return;
|
||||
|
||||
for(int i=1;i<vec.size();++i)
|
||||
{//后面的键值出现的位置为前面所有键值出现的次数之和
|
||||
range[i]+=range[i-1];
|
||||
}
|
||||
//至此,range中存放的是相应键值应该出现的位置
|
||||
int length=vec.size();
|
||||
for(int i=length-1;i>=0;--i) //注意一个小细节,统计时最正序的,这里是逆序
|
||||
{//如果存在相同的键值,为了保持稳定性,后出现的应该还是位于后面
|
||||
//如果正序,则先出现的会放置到后面,因此不再稳定
|
||||
objVec[range[vec[i]]]=vec[i]; //将键值放到目标位置
|
||||
range[vec[i]]--;
|
||||
}
|
||||
// 使用 vecRaw 的最大值 + 1 作为计数容器 countVec 的大小
|
||||
int vecCountLength = (*max_element(begin(vecRaw), end(vecRaw))) + 1;
|
||||
vector<int> vecCount(vecCountLength, 0);
|
||||
|
||||
// 统计每个键值出现的次数
|
||||
for (int i = 0; i < vecRaw.size(); i++)
|
||||
vecCount[vecRaw[i]]++;
|
||||
|
||||
// 后面的键值出现的位置为前面所有键值出现的次数之和
|
||||
for (int i = 1; i < vecCountLength; i++)
|
||||
vecCount[i] += vecCount[i - 1];
|
||||
|
||||
// 将键值放到目标位置
|
||||
for (int i = vecRaw.size(); i > 0; i--) // 此处逆序是为了保持相同键值的稳定性
|
||||
vecObj[--vecCount[vecRaw[i - 1]]] = vecRaw[i - 1];
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int a[14]={0,5,7,9,6,3,4,5,2,8,6,9,2,1};
|
||||
vector<int> vec(a,a+14);
|
||||
vector<int> objVec(14,0);
|
||||
vector<int> vecRaw = { 0,5,7,9,6,3,4,5,2,8,6,9,2,1 };
|
||||
vector<int> vecObj(vecRaw.size(), 0);
|
||||
|
||||
countSort(vec,objVec);
|
||||
CountSort(vecRaw, vecObj);
|
||||
|
||||
for(int i=0;i<objVec.size();++i)
|
||||
cout<<objVec[i]<<" ";
|
||||
cout<<endl;
|
||||
for (int i = 0; i < vecObj.size(); ++i)
|
||||
cout << vecObj[i] << " ";
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
360
LICENSE
Normal file
360
LICENSE
Normal file
|
@ -0,0 +1,360 @@
|
|||
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
||||
Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree
|
||||
to be bound by the terms and conditions of this Creative Commons
|
||||
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
||||
("Public License"). To the extent this Public License may be
|
||||
interpreted as a contract, You are granted the Licensed Rights in
|
||||
consideration of Your acceptance of these terms and conditions, and the
|
||||
Licensor grants You such rights in consideration of benefits the
|
||||
Licensor receives from making the Licensed Material available under
|
||||
these terms and conditions.
|
||||
|
||||
|
||||
Section 1 -- Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar
|
||||
Rights that is derived from or based upon the Licensed Material
|
||||
and in which the Licensed Material is translated, altered,
|
||||
arranged, transformed, or otherwise modified in a manner requiring
|
||||
permission under the Copyright and Similar Rights held by the
|
||||
Licensor. For purposes of this Public License, where the Licensed
|
||||
Material is a musical work, performance, or sound recording,
|
||||
Adapted Material is always produced where the Licensed Material is
|
||||
synched in timed relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright
|
||||
and Similar Rights in Your contributions to Adapted Material in
|
||||
accordance with the terms and conditions of this Public License.
|
||||
|
||||
c. BY-NC-SA Compatible License means a license listed at
|
||||
creativecommons.org/compatiblelicenses, approved by Creative
|
||||
Commons as essentially the equivalent of this Public License.
|
||||
|
||||
d. Copyright and Similar Rights means copyright and/or similar rights
|
||||
closely related to copyright including, without limitation,
|
||||
performance, broadcast, sound recording, and Sui Generis Database
|
||||
Rights, without regard to how the rights are labeled or
|
||||
categorized. For purposes of this Public License, the rights
|
||||
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||
Rights.
|
||||
|
||||
e. Effective Technological Measures means those measures that, in the
|
||||
absence of proper authority, may not be circumvented under laws
|
||||
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||
Treaty adopted on December 20, 1996, and/or similar international
|
||||
agreements.
|
||||
|
||||
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||
any other exception or limitation to Copyright and Similar Rights
|
||||
that applies to Your use of the Licensed Material.
|
||||
|
||||
g. License Elements means the license attributes listed in the name
|
||||
of a Creative Commons Public License. The License Elements of this
|
||||
Public License are Attribution, NonCommercial, and ShareAlike.
|
||||
|
||||
h. Licensed Material means the artistic or literary work, database,
|
||||
or other material to which the Licensor applied this Public
|
||||
License.
|
||||
|
||||
i. Licensed Rights means the rights granted to You subject to the
|
||||
terms and conditions of this Public License, which are limited to
|
||||
all Copyright and Similar Rights that apply to Your use of the
|
||||
Licensed Material and that the Licensor has authority to license.
|
||||
|
||||
j. Licensor means the individual(s) or entity(ies) granting rights
|
||||
under this Public License.
|
||||
|
||||
k. NonCommercial means not primarily intended for or directed towards
|
||||
commercial advantage or monetary compensation. For purposes of
|
||||
this Public License, the exchange of the Licensed Material for
|
||||
other material subject to Copyright and Similar Rights by digital
|
||||
file-sharing or similar means is NonCommercial provided there is
|
||||
no payment of monetary compensation in connection with the
|
||||
exchange.
|
||||
|
||||
l. Share means to provide material to the public by any means or
|
||||
process that requires permission under the Licensed Rights, such
|
||||
as reproduction, public display, public performance, distribution,
|
||||
dissemination, communication, or importation, and to make material
|
||||
available to the public including in ways that members of the
|
||||
public may access the material from a place and at a time
|
||||
individually chosen by them.
|
||||
|
||||
m. Sui Generis Database Rights means rights other than copyright
|
||||
resulting from Directive 96/9/EC of the European Parliament and of
|
||||
the Council of 11 March 1996 on the legal protection of databases,
|
||||
as amended and/or succeeded, as well as other essentially
|
||||
equivalent rights anywhere in the world.
|
||||
|
||||
n. You means the individual or entity exercising the Licensed Rights
|
||||
under this Public License. Your has a corresponding meaning.
|
||||
|
||||
|
||||
Section 2 -- Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License,
|
||||
the Licensor hereby grants You a worldwide, royalty-free,
|
||||
non-sublicensable, non-exclusive, irrevocable license to
|
||||
exercise the Licensed Rights in the Licensed Material to:
|
||||
|
||||
a. reproduce and Share the Licensed Material, in whole or
|
||||
in part, for NonCommercial purposes only; and
|
||||
|
||||
b. produce, reproduce, and Share Adapted Material for
|
||||
NonCommercial purposes only.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||
Exceptions and Limitations apply to Your use, this Public
|
||||
License does not apply, and You do not need to comply with
|
||||
its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section
|
||||
6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The
|
||||
Licensor authorizes You to exercise the Licensed Rights in
|
||||
all media and formats whether now known or hereafter created,
|
||||
and to make technical modifications necessary to do so. The
|
||||
Licensor waives and/or agrees not to assert any right or
|
||||
authority to forbid You from making technical modifications
|
||||
necessary to exercise the Licensed Rights, including
|
||||
technical modifications necessary to circumvent Effective
|
||||
Technological Measures. For purposes of this Public License,
|
||||
simply making modifications authorized by this Section 2(a)
|
||||
(4) never produces Adapted Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
a. Offer from the Licensor -- Licensed Material. Every
|
||||
recipient of the Licensed Material automatically
|
||||
receives an offer from the Licensor to exercise the
|
||||
Licensed Rights under the terms and conditions of this
|
||||
Public License.
|
||||
|
||||
b. Additional offer from the Licensor -- Adapted Material.
|
||||
Every recipient of Adapted Material from You
|
||||
automatically receives an offer from the Licensor to
|
||||
exercise the Licensed Rights in the Adapted Material
|
||||
under the conditions of the Adapter's License You apply.
|
||||
|
||||
c. No downstream restrictions. You may not offer or impose
|
||||
any additional or different terms or conditions on, or
|
||||
apply any Effective Technological Measures to, the
|
||||
Licensed Material if doing so restricts exercise of the
|
||||
Licensed Rights by any recipient of the Licensed
|
||||
Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or
|
||||
may be construed as permission to assert or imply that You
|
||||
are, or that Your use of the Licensed Material is, connected
|
||||
with, or sponsored, endorsed, or granted official status by,
|
||||
the Licensor or others designated to receive attribution as
|
||||
provided in Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not
|
||||
licensed under this Public License, nor are publicity,
|
||||
privacy, and/or other similar personality rights; however, to
|
||||
the extent possible, the Licensor waives and/or agrees not to
|
||||
assert any such rights held by the Licensor to the limited
|
||||
extent necessary to allow You to exercise the Licensed
|
||||
Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this
|
||||
Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to
|
||||
collect royalties from You for the exercise of the Licensed
|
||||
Rights, whether directly or through a collecting society
|
||||
under any voluntary or waivable statutory or compulsory
|
||||
licensing scheme. In all other cases the Licensor expressly
|
||||
reserves any right to collect such royalties, including when
|
||||
the Licensed Material is used other than for NonCommercial
|
||||
purposes.
|
||||
|
||||
|
||||
Section 3 -- License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the
|
||||
following conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified
|
||||
form), You must:
|
||||
|
||||
a. retain the following if it is supplied by the Licensor
|
||||
with the Licensed Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed
|
||||
Material and any others designated to receive
|
||||
attribution, in any reasonable manner requested by
|
||||
the Licensor (including by pseudonym if
|
||||
designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of
|
||||
warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the
|
||||
extent reasonably practicable;
|
||||
|
||||
b. indicate if You modified the Licensed Material and
|
||||
retain an indication of any previous modifications; and
|
||||
|
||||
c. indicate the Licensed Material is licensed under this
|
||||
Public License, and include the text of, or the URI or
|
||||
hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||
reasonable manner based on the medium, means, and context in
|
||||
which You Share the Licensed Material. For example, it may be
|
||||
reasonable to satisfy the conditions by providing a URI or
|
||||
hyperlink to a resource that includes the required
|
||||
information.
|
||||
3. If requested by the Licensor, You must remove any of the
|
||||
information required by Section 3(a)(1)(A) to the extent
|
||||
reasonably practicable.
|
||||
|
||||
b. ShareAlike.
|
||||
|
||||
In addition to the conditions in Section 3(a), if You Share
|
||||
Adapted Material You produce, the following conditions also apply.
|
||||
|
||||
1. The Adapter's License You apply must be a Creative Commons
|
||||
license with the same License Elements, this version or
|
||||
later, or a BY-NC-SA Compatible License.
|
||||
|
||||
2. You must include the text of, or the URI or hyperlink to, the
|
||||
Adapter's License You apply. You may satisfy this condition
|
||||
in any reasonable manner based on the medium, means, and
|
||||
context in which You Share Adapted Material.
|
||||
|
||||
3. You may not offer or impose any additional or different terms
|
||||
or conditions on, or apply any Effective Technological
|
||||
Measures to, Adapted Material that restrict exercise of the
|
||||
rights granted under the Adapter's License You apply.
|
||||
|
||||
|
||||
Section 4 -- Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that
|
||||
apply to Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||
to extract, reuse, reproduce, and Share all or a substantial
|
||||
portion of the contents of the database for NonCommercial purposes
|
||||
only;
|
||||
|
||||
b. if You include all or a substantial portion of the database
|
||||
contents in a database in which You have Sui Generis Database
|
||||
Rights, then the database in which You have Sui Generis Database
|
||||
Rights (but not its individual contents) is Adapted Material,
|
||||
including for purposes of Section 3(b); and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share
|
||||
all or a substantial portion of the contents of the database.
|
||||
|
||||
For the avoidance of doubt, this Section 4 supplements and does not
|
||||
replace Your obligations under this Public License where the Licensed
|
||||
Rights include other Copyright and Similar Rights.
|
||||
|
||||
|
||||
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||
|
||||
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided
|
||||
above shall be interpreted in a manner that, to the extent
|
||||
possible, most closely approximates an absolute disclaimer and
|
||||
waiver of all liability.
|
||||
|
||||
|
||||
Section 6 -- Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and
|
||||
Similar Rights licensed here. However, if You fail to comply with
|
||||
this Public License, then Your rights under this Public License
|
||||
terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under
|
||||
Section 6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided
|
||||
it is cured within 30 days of Your discovery of the
|
||||
violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||
right the Licensor may have to seek remedies for Your violations
|
||||
of this Public License.
|
||||
|
||||
c. For the avoidance of doubt, the Licensor may also offer the
|
||||
Licensed Material under separate terms or conditions or stop
|
||||
distributing the Licensed Material at any time; however, doing so
|
||||
will not terminate this Public License.
|
||||
|
||||
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||
License.
|
||||
|
||||
|
||||
Section 7 -- Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different
|
||||
terms or conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the
|
||||
Licensed Material not stated herein are separate from and
|
||||
independent of the terms and conditions of this Public License.
|
||||
|
||||
|
||||
Section 8 -- Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and
|
||||
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||
conditions on any use of the Licensed Material that could lawfully
|
||||
be made without permission under this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is
|
||||
deemed unenforceable, it shall be automatically reformed to the
|
||||
minimum extent necessary to make it enforceable. If the provision
|
||||
cannot be reformed, it shall be severed from this Public License
|
||||
without affecting the enforceability of the remaining terms and
|
||||
conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no
|
||||
failure to comply consented to unless expressly agreed to by the
|
||||
Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted
|
||||
as a limitation upon, or waiver of, any privileges and immunities
|
||||
that apply to the Licensor or You, including from the legal
|
||||
processes of any jurisdiction or authority.
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
某算法从一个1×1的方格开始,每次都会在上次图形的周围再加上一圈方格,在第n次的时候要生成多少个方格?下图给出了n = 0,1,2是的结果。
|
||||
|
||||
![](http://ojlsgreog.bkt.clouddn.com/NeumannNeighborProblem.jpg)
|
||||
![](https://huihut-img.oss-cn-shenzhen.aliyuncs.com/NeumannNeighborProblem.jpg)
|
||||
|
||||
### 功能说明
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
某算法从一个1×1的方格开始,每次都会在上次图形的周围再加上一圈方格,在第n次的时候要生成多少个方格?下图给出了n = 0,1,2是的结果。
|
||||
|
||||
![](http://ojlsgreog.bkt.clouddn.com/NeumannNeighborProblem.jpg)
|
||||
![](https://huihut-img.oss-cn-shenzhen.aliyuncs.com/NeumannNeighborProblem.jpg)
|
||||
|
||||
### 解法
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
某算法从一个1×1的方格开始,每次都会在上次图形的周围再加上一圈方格,在第n次的时候要生成多少个方格?下图给出了n = 0,1,2是的结果。
|
||||
|
||||
![](http://ojlsgreog.bkt.clouddn.com/NeumannNeighborProblem.jpg)
|
||||
![](https://huihut-img.oss-cn-shenzhen.aliyuncs.com/NeumannNeighborProblem.jpg)
|
||||
|
||||
### 功能说明
|
||||
|
||||
|
|
347
README.md
347
README.md
|
@ -1,35 +1,18 @@
|
|||
# C/C++ 面试知识总结
|
||||
|
||||
C/C++ 面试知识总结,只为复习、分享。部分知识点与图片来自网络,侵删。
|
||||
C/C++ 面试基础知识总结,只为复习、分享。勘误新增请 [Issue](https://github.com/huihut/interview/issues)、[PR](https://github.com/huihut/interview/pulls),建议、讨论请移步 [issues/12](https://github.com/huihut/interview/issues/12),排版使用 [中文文案排版指北](https://github.com/mzlogin/chinese-copywriting-guidelines),版权协议遵循 [CC BY-NC-SA 4.0](#License)。
|
||||
|
||||
勘误请 Issue、Pull,新增请 Issue,建议、讨论请 [# issues/12](https://github.com/huihut/interview/issues/12)
|
||||
<br>
|
||||
|
||||
## 使用建议
|
||||
<b><details><summary>💡 提示</summary></b>
|
||||
|
||||
* `Ctrl + F`:快速查找定位知识点
|
||||
* `TOC 导航`:使用 [jawil/GayHub](https://github.com/jawil/GayHub) 插件快速目录跳转
|
||||
* `T`:按 `T` 激活文件查找器快速查找 / 跳转文件
|
||||
右侧目录支持方式:
|
||||
|
||||
## 目录
|
||||
* 语雀的镜像仓库:[C/C++ 面试基础知识总结](https://www.yuque.com/huihut/interview/readme)
|
||||
* Github + TOC:[jawil/GayHub TOC 导航](https://github.com/jawil/GayHub)
|
||||
|
||||
* [C/C++](#cc)
|
||||
* [STL](#stl)
|
||||
* [数据结构](#%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84)
|
||||
* [算法](#%E7%AE%97%E6%B3%95)
|
||||
* [Problems](#problems)
|
||||
* [操作系统](#%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F)
|
||||
* [计算机网络](#%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C)
|
||||
* [网络编程](#%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B)
|
||||
* [数据库](#%E6%95%B0%E6%8D%AE%E5%BA%93)
|
||||
* [设计模式](#%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)
|
||||
* [链接装载库](#%E9%93%BE%E6%8E%A5%E8%A3%85%E8%BD%BD%E5%BA%93)
|
||||
* [海量数据处理](#%E6%B5%B7%E9%87%8F%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86)
|
||||
* [音视频](#%E9%9F%B3%E8%A7%86%E9%A2%91)
|
||||
* [其他](#%E5%85%B6%E4%BB%96)
|
||||
* [书籍](#%E4%B9%A6%E7%B1%8D)
|
||||
* [复习刷题网站](#%E5%A4%8D%E4%B9%A0%E5%88%B7%E9%A2%98%E7%BD%91%E7%AB%99)
|
||||
* [招聘时间岗位](#%E6%8B%9B%E8%81%98%E6%97%B6%E9%97%B4%E5%B2%97%E4%BD%8D)
|
||||
* [面试题目经验](#%E9%9D%A2%E8%AF%95%E9%A2%98%E7%9B%AE%E7%BB%8F%E9%AA%8C)
|
||||
</details>
|
||||
|
||||
<b><details><summary>➕ C/C++</summary></b>
|
||||
|
||||
## C/C++
|
||||
|
||||
|
@ -122,7 +105,7 @@ int* const function7(); // 返回一个指向变量的常指针,使用:i
|
|||
* 相当于不用执行进入函数的步骤,直接执行函数体;
|
||||
* 相当于宏,却比宏多了类型检查,真正具有函数特性;
|
||||
* 不能包含循环、递归、switch 等复杂操作;
|
||||
* 类中除了虚函数的其他函数都会自动隐式地当成内联函数。
|
||||
* 在类声明中定义的函数,除了虚函数的其他函数都会自动隐式地当成内联函数。
|
||||
|
||||
#### 使用
|
||||
|
||||
|
@ -138,6 +121,17 @@ int functionName(int first, int secend,...);
|
|||
|
||||
// 定义
|
||||
inline int functionName(int first, int secend,...) {/****/};
|
||||
|
||||
// 类内定义,隐式内联
|
||||
class A {
|
||||
int doA() { return 0; } // 隐式内联
|
||||
}
|
||||
|
||||
// 类外定义,需要显式内联
|
||||
class A {
|
||||
int doA();
|
||||
}
|
||||
inline int A::doA() { return 0; } // 需要显式内联
|
||||
```
|
||||
|
||||
</details>
|
||||
|
@ -166,7 +160,7 @@ inline int functionName(int first, int secend,...) {/****/};
|
|||
|
||||
#### 虚函数(virtual)可以是内联函数(inline)吗?
|
||||
|
||||
[Are "inline virtual" member functions ever actually "inlined"?](http://www.cs.technion.ac.il/users/yechiel/c++-faq/inline-virtuals.html)
|
||||
> [Are "inline virtual" member functions ever actually "inlined"?](http://www.cs.technion.ac.il/users/yechiel/c++-faq/inline-virtuals.html)
|
||||
|
||||
* 虚函数可以是内联函数,内联是可以修饰虚函数的,但是当虚函数表现多态性的时候不能内联。
|
||||
* 内联是在编译器建议编译器内联,而虚函数的多态性在运行期,编译器无法知道运行期调用哪个代码,因此虚函数表现为多态性时(运行期)不可以内联。
|
||||
|
@ -219,12 +213,19 @@ int main()
|
|||
|
||||
### assert()
|
||||
|
||||
断言,是宏,而非函数。assert 宏的原型定义在`<assert.h>`(C)、`<cassert>`(C++)中,其作用是如果它的条件返回错误,则终止程序执行。如:
|
||||
断言,是宏,而非函数。assert 宏的原型定义在 `<assert.h>`(C)、`<cassert>`(C++)中,其作用是如果它的条件返回错误,则终止程序执行。可以通过定义 `NDEBUG` 来关闭 assert,但是需要在源代码的开头,`include <assert.h>` 之前。
|
||||
|
||||
<details><summary>assert() 使用</summary>
|
||||
|
||||
```cpp
|
||||
assert( p != NULL );
|
||||
#define NDEBUG // 加上这行,则 assert 不可用
|
||||
#include <assert.h>
|
||||
|
||||
assert( p != NULL ); // assert 不可用
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### sizeof()
|
||||
|
||||
* sizeof 对数组,得到整个数组所占空间大小。
|
||||
|
@ -423,42 +424,56 @@ int main() {
|
|||
|
||||
### C 实现 C++ 类
|
||||
|
||||
[C 语言实现封装、继承和多态](http://dongxicheng.org/cpp/ooc/)
|
||||
> [C 语言实现封装、继承和多态](http://dongxicheng.org/cpp/ooc/)
|
||||
|
||||
### explicit(显式)构造函数
|
||||
### explicit(显式)关键字
|
||||
|
||||
explicit 修饰的构造函数可用来防止隐式转换
|
||||
* explicit 修饰构造函数时,可以防止隐式转换和复制初始化
|
||||
* explicit 修饰转换函数时,可以防止隐式转换,但 [按语境转换](https://zh.cppreference.com/w/cpp/language/implicit_conversion) 除外
|
||||
|
||||
<details><summary>explicit 使用</summary>
|
||||
|
||||
```cpp
|
||||
class Test1
|
||||
struct A
|
||||
{
|
||||
public:
|
||||
Test1(int n) // 普通构造函数
|
||||
{
|
||||
num=n;
|
||||
}
|
||||
private:
|
||||
int num;
|
||||
A(int) { }
|
||||
operator bool() const { return true; }
|
||||
};
|
||||
|
||||
class Test2
|
||||
struct B
|
||||
{
|
||||
public:
|
||||
explicit Test2(int n) // explicit(显式)构造函数
|
||||
{
|
||||
num=n;
|
||||
}
|
||||
private:
|
||||
int num;
|
||||
explicit B(int) {}
|
||||
explicit operator bool() const { return true; }
|
||||
};
|
||||
|
||||
void doA(A a) {}
|
||||
|
||||
void doB(B b) {}
|
||||
|
||||
int main()
|
||||
{
|
||||
Test1 t1=12; // 隐式调用其构造函数,成功
|
||||
Test2 t2=12; // 编译错误,不能隐式调用其构造函数
|
||||
Test2 t2(12); // 显式调用成功
|
||||
A a1(1); // OK:直接初始化
|
||||
A a2 = 1; // OK:复制初始化
|
||||
A a3{ 1 }; // OK:直接列表初始化
|
||||
A a4 = { 1 }; // OK:复制列表初始化
|
||||
A a5 = (A)1; // OK:允许 static_cast 的显式转换
|
||||
doA(1); // OK:允许从 int 到 A 的隐式转换
|
||||
if (a1); // OK:使用转换函数 A::operator bool() 的从 A 到 bool 的隐式转换
|
||||
bool a6(a1); // OK:使用转换函数 A::operator bool() 的从 A 到 bool 的隐式转换
|
||||
bool a7 = a1; // OK:使用转换函数 A::operator bool() 的从 A 到 bool 的隐式转换
|
||||
bool a8 = static_cast<bool>(a1); // OK :static_cast 进行直接初始化
|
||||
|
||||
B b1(1); // OK:直接初始化
|
||||
B b2 = 1; // 错误:被 explicit 修饰构造函数的对象不可以复制初始化
|
||||
B b3{ 1 }; // OK:直接列表初始化
|
||||
B b4 = { 1 }; // 错误:被 explicit 修饰构造函数的对象不可以复制列表初始化
|
||||
B b5 = (B)1; // OK:允许 static_cast 的显式转换
|
||||
doB(1); // 错误:被 explicit 修饰构造函数的对象不可以从 int 到 B 的隐式转换
|
||||
if (b1); // OK:被 explicit 修饰转换函数 B::operator bool() 的对象可以从 B 到 bool 的按语境转换
|
||||
bool b6(b1); // OK:被 explicit 修饰转换函数 B::operator bool() 的对象可以从 B 到 bool 的按语境转换
|
||||
bool b7 = b1; // 错误:被 explicit 修饰转换函数 B::operator bool() 的对象不可以隐式转换
|
||||
bool b8 = static_cast<bool>(b1); // OK:static_cast 进行直接初始化
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
@ -847,12 +862,12 @@ virtual int A() = 0;
|
|||
|
||||
### 虚函数、纯虚函数
|
||||
|
||||
[CSDN . C++ 中的虚函数、纯虚函数区别和联系](https://blog.csdn.net/u012260238/article/details/53610462)
|
||||
> [CSDN . C++ 中的虚函数、纯虚函数区别和联系](https://blog.csdn.net/u012260238/article/details/53610462)
|
||||
|
||||
* 类里如果声明了虚函数,这个函数是实现的,哪怕是空实现,它的作用就是为了能让这个函数在它的子类里面可以被覆盖,这样的话,这样编译器就可以使用后期绑定来达到多态了。纯虚函数只是一个接口,是个函数的声明而已,它要留到子类里去实现。
|
||||
* 虚函数在子类里面也可以不重载的;但纯虚函数必须在子类去实现。
|
||||
* 虚函数的类用于 “实作继承”,继承接口的同时也继承了父类的实现。当然大家也可以完成自己的实现。纯虚函数关注的是接口的统一性,实现由子类完成。
|
||||
* 带纯虚函数的类叫虚基类,这种基类不能直接生成对象,而只有被继承,并重写其虚函数后,才能使用。这样的类也叫抽象类。抽象类和大家口头常说的虚基类还是有区别的,在 C# 中用 abstract 定义抽象类,而在 C++ 中有抽象类的概念,但是没有这个关键字。抽象类被继承后,子类可以继续是抽象类,也可以是普通类,而虚基类,是含有纯虚函数的类,它如果被继承,那么子类就必须实现虚基类里面的所有纯虚函数,其子类不能是抽象类。
|
||||
* 带纯虚函数的类叫抽象类,这种类不能直接生成对象,而只有被继承,并重写其虚函数后,才能使用。抽象类和大家口头常说的虚基类还是有区别的,在 C# 中用 abstract 定义抽象类,而在 C++ 中有抽象类的概念,但是没有这个关键字。抽象类被继承后,子类可以继续是抽象类,也可以是普通类,而虚基类,是含有纯虚函数的类,它如果被继承,那么子类就必须实现虚基类里面的所有纯虚函数,其子类不能是抽象类。
|
||||
|
||||
### 虚函数指针、虚函数表
|
||||
|
||||
|
@ -961,7 +976,7 @@ new (palce_address) type [size] { braced initializer list }
|
|||
|
||||
### delete this 合法吗?
|
||||
|
||||
[Is it legal (and moral) for a member function to say delete this?](https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
|
||||
> [Is it legal (and moral) for a member function to say delete this?](https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
|
||||
|
||||
合法,但:
|
||||
|
||||
|
@ -972,7 +987,7 @@ new (palce_address) type [size] { braced initializer list }
|
|||
|
||||
### 如何定义一个只能在堆上(栈上)生成对象的类?
|
||||
|
||||
[如何定义一个只能在堆上(栈上)生成对象的类?](https://www.nowcoder.com/questionTerminal/0a584aa13f804f3ea72b442a065a7618)
|
||||
> [如何定义一个只能在堆上(栈上)生成对象的类?](https://www.nowcoder.com/questionTerminal/0a584aa13f804f3ea72b442a065a7618)
|
||||
|
||||
#### 只能在堆上
|
||||
|
||||
|
@ -1037,7 +1052,7 @@ unique_ptr 是 C++11 才开始提供的类型,是一种在异常时可以帮
|
|||
|
||||
### 强制类型转换运算符
|
||||
|
||||
[MSDN . 强制转换运算符](https://msdn.microsoft.com/zh-CN/library/5f6c9f8h.aspx)
|
||||
> [MSDN . 强制转换运算符](https://msdn.microsoft.com/zh-CN/library/5f6c9f8h.aspx)
|
||||
|
||||
#### static_cast
|
||||
|
||||
|
@ -1161,7 +1176,7 @@ class doSomething(Flyable *obj) // 做些事情
|
|||
### Effective C++
|
||||
|
||||
1. 视 C++ 为一个语言联邦(C、Object-Oriented C++、Template C++、STL)
|
||||
2. 尽量以 `const`、`enum`、`inline` 替换 `#define`(宁可以编译器替换预处理器)
|
||||
2. 宁可以编译器替换预处理器(尽量以 `const`、`enum`、`inline` 替换 `#define`)
|
||||
3. 尽可能使用 const
|
||||
4. 确定对象被使用前已先被初始化(构造时赋值(copy 构造函数)比 default 构造后赋值(copy assignment)效率高)
|
||||
5. 了解 C++ 默默编写并调用哪些函数(编译器暗自为 class 创建 default 构造函数、copy 构造函数、copy assignment 操作符、析构函数)
|
||||
|
@ -1188,43 +1203,91 @@ class doSomething(Flyable *obj) // 做些事情
|
|||
26. 尽可能延后变量定义式的出现时间(可增加程序清晰度并改善程序效率)
|
||||
27. 尽量少做转型动作(旧式:`(T)expression`、`T(expression)`;新式:`const_cast<T>(expression)`、`dynamic_cast<T>(expression)`、`reinterpret_cast<T>(expression)`、`static_cast<T>(expression)`、;尽量避免转型、注重效率避免 dynamic_casts、尽量设计成无需转型、可把转型封装成函数、宁可用新式转型)
|
||||
28. 避免使用 handles(包括 引用、指针、迭代器)指向对象内部(以增加封装性、使 const 成员函数的行为更像 const、降低 “虚吊号码牌”(dangling handles,如悬空指针等)的可能性)
|
||||
|
||||
29. 为 “异常安全” 而努力是值得的(异常安全函数(Exception-safe functions)即使发生异常也不会泄露资源或允许任何数据结构败坏,分为三种可能的保证:基本型、强列型、不抛异常型)
|
||||
30. 透彻了解 inlining 的里里外外(inlining 在大多数 C++ 程序中是编译期的行为;inline 函数是否真正 inline,取决于编译器;大部分编译器拒绝太过复杂(如带有循环或递归)的函数 inlining,而所有对 virtual 函数的调用(除非是最平淡无奇的)也都会使 inlining 落空;inline 造成的代码膨胀可能带来效率损失;inline 函数无法随着程序库的升级而升级)
|
||||
31. 将文件间的编译依存关系降至最低(如果使用 object references 或 object pointers 可以完成任务,就不要使用 objects;如果能过够,尽量以 class 声明式替换 class 定义式;为声明式和定义式提供不同的头文件)
|
||||
32. 确定你的 public 继承塑模出 is-a(是一种)关系(适用于 base classes 身上的每一件事情一定适用于 derived classes 身上,因为每一个 derived class 对象也都是一个 base class 对象)
|
||||
33. 避免遮掩继承而来的名字(可使用 using 声明式或转交函数(forwarding functions)来让被遮掩的名字再见天日)
|
||||
34. 区分接口继承和实现继承(在 public 继承之下,derived classes 总是继承 base class 的接口;pure virtual 函数只具体指定接口继承;非纯 impure virtual 函数具体指定接口继承及缺省实现继承;non-virtual 函数具体指定接口继承以及强制性实现继承)
|
||||
35. 考虑 virtual 函数以外的其他选择(如 Template Method 设计模式的 non-virtual interface(NVI)手法,将 virtual 函数替换为 “函数指针成员变量”,以 `tr1::function` 成员变量替换 virtual 函数,将继承体系内的 virtual 函数替换为另一个继承体系内的 virtual 函数)
|
||||
36. 绝不重新定义继承而来的 non-virtual 函数
|
||||
37. 绝不重新定义继承而来的缺省参数值,因为缺省参数值是静态绑定(statically bound),而 virtual 函数却是动态绑定(dynamically bound)
|
||||
38. 通过复合塑模 has-a(有一个)或 “根据某物实现出”(在应用域(application domain),复合意味 has-a(有一个);在实现域(implementation domain),复合意味着 is-implemented-in-terms-of(根据某物实现出))
|
||||
39. 明智而审慎地使用 private 继承(private 继承意味着 is-implemented-in-terms-of(根据某物实现出),尽可能使用复合,当 derived class 需要访问 protected base class 的成员,或需要重新定义继承而来的时候 virtual 函数,或需要 empty base 最优化时,才使用 private 继承)
|
||||
40. 明智而审慎地使用多重继承(多继承比单一继承复杂,可能导致新的歧义性,以及对 virtual 继承的需要,但确有正当用途,如 “public 继承某个 interface class” 和 “private 继承某个协助实现的 class”;virtual 继承可解决多继承下菱形继承的二义性问题,但会增加大小、速度、初始化及赋值的复杂度等等成本)
|
||||
41. 了解隐式接口和编译期多态(class 和 templates 都支持接口(interfaces)和多态(polymorphism);class 的接口是以签名为中心的显式的(explicit),多态则是通过 virtual 函数发生于运行期;template 的接口是奠基于有效表达式的隐式的(implicit),多态则是通过 template 具现化和函数重载解析(function overloading resolution)发生于编译期)
|
||||
42. 了解 typename 的双重意义(声明 template 类型参数是,前缀关键字 class 和 typename 的意义完全相同;请使用关键字 typename 标识嵌套从属类型名称,但不得在基类列(base class lists)或成员初值列(member initialization list)内以它作为 basee class 修饰符)
|
||||
43. 学习处理模板化基类内的名称(可在 derived class templates 内通过 `this->` 指涉 base class templates 内的成员名称,或藉由一个明白写出的 “base class 资格修饰符” 完成)
|
||||
44. 将与参数无关的代码抽离 templates(因类型模板参数(non-type template parameters)而造成代码膨胀往往可以通过函数参数或 class 成员变量替换 template 参数来消除;因类型参数(type parameters)而造成的代码膨胀往往可以通过让带有完全相同二进制表述(binary representations)的实现类型(instantiation types)共享实现码)
|
||||
45. 运用成员函数模板接受所有兼容类型(请使用成员函数模板(member function templates)生成 “可接受所有兼容类型” 的函数;声明 member templates 用于 “泛化 copy 构造” 或 “泛化 assignment 操作” 时还需要声明正常的 copy 构造函数和 copy assignment 操作符)
|
||||
46. 需要类型转换时请为模板定义非成员函数(当我们编写一个 class template,而它所提供之 “与此 template 相关的” 函数支持 “所有参数之隐式类型转换” 时,请将那些函数定义为 “class template 内部的 friend 函数”)
|
||||
47. 请使用 traits classes 表现类型信息(traits classes 通过 templates 和 “templates 特化” 使得 “类型相关信息” 在编译期可用,通过重载技术(overloading)实现在编译期对类型执行 if...else 测试)
|
||||
48. 认识 template 元编程(模板元编程(TMP,template metaprogramming)可将工作由运行期移往编译期,因此得以实现早期错误侦测和更高的执行效率;TMP 可被用来生成 “给予政策选择组合”(based on combinations of policy choices)的客户定制代码,也可用来避免生成对某些特殊类型并不适合的代码)
|
||||
49. 了解 new-handler 的行为(set\_new\_handler 允许客户指定一个在内存分配无法获得满足时被调用的函数;nothrow new 是一个颇具局限的工具,因为它只适用于内存分配(operator new),后继的构造函数调用还是可能抛出异常)
|
||||
50. 了解 new 和 delete 的合理替换时机(为了检测运用错误、收集动态分配内存之使用统计信息、增加分配和归还速度、降低缺省内存管理器带来的空间额外开销、弥补缺省分配器中的非最佳齐位、将相关对象成簇集中、获得非传统的行为)
|
||||
51. 编写 new 和 delete 时需固守常规(operator new 应该内涵一个无穷循环,并在其中尝试分配内存,如果它无法满足内存需求,就应该调用 new-handler,它也应该有能力处理 0 bytes 申请,class 专属版本则还应该处理 “比正确大小更大的(错误)申请”;operator delete 应该在收到 null 指针时不做任何事,class 专属版本则还应该处理 “比正确大小更大的(错误)申请”)
|
||||
52. 写了 placement new 也要写 placement delete(当你写一个 placement operator new,请确定也写出了对应的 placement operator delete,否则可能会发生隐微而时断时续的内存泄漏;当你声明 placement new 和 placement delete,请确定不要无意识(非故意)地遮掩了它们地正常版本)
|
||||
53. 不要轻忽编译器的警告
|
||||
54. 让自己熟悉包括 TR1 在内的标准程序库(TR1,C++ Technical Report 1,C++11 标准的草稿文件)
|
||||
55. 让自己熟悉 Boost(准标准库)
|
||||
|
||||
### Google C++ Style Guide
|
||||
|
||||
> 英文:[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
|
||||
> 中文:[C++ 风格指南](https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/contents/)
|
||||
<details><summary>Google C++ Style Guide 图</summary>
|
||||
|
||||
![Google C++ Style Guide](http://img.blog.csdn.net/20140713220242000)
|
||||
![Google C++ Style Guide](images/GoogleCppStyleGuide.png)
|
||||
|
||||
> 图片来源于:[CSDN . 一张图总结Google C++编程规范(Google C++ Style Guide)](http://blog.csdn.net/voidccc/article/details/37599203)
|
||||
> 图片来源于:[CSDN . 一张图总结Google C++编程规范(Google C++ Style Guide)](https://blog.csdn.net/voidccc/article/details/37599203)
|
||||
|
||||
</details>
|
||||
|
||||
### 其他
|
||||
|
||||
* [Bjarne Stroustrup 的常见问题](http://www.stroustrup.com/bs_faq.html)
|
||||
* [Bjarne Stroustrup 的 C++ 风格和技巧常见问题](http://www.stroustrup.com/bs_faq2.html)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>📦 STL</summary></b>
|
||||
|
||||
## STL
|
||||
|
||||
### 索引
|
||||
### STL 索引
|
||||
|
||||
[STL 方法含义](https://github.com/huihut/interview/tree/master/STL)
|
||||
[STL 方法含义索引](https://github.com/huihut/interview/tree/master/STL)
|
||||
|
||||
### 容器
|
||||
### STL 容器
|
||||
|
||||
容器 | 底层数据结构 | 有无序 | 可不可重复 | 其他
|
||||
---|---|---|---|---
|
||||
[array](https://github.com/huihut/interview/tree/master/STL#array)|数组|无序|可重复|支持快速随机访问
|
||||
[vector](https://github.com/huihut/interview/tree/master/STL#vector)|数组|无序|可重复|支持快速随机访问
|
||||
[list](https://github.com/huihut/interview/tree/master/STL#list)|双向链表|无序|可重复|支持快速增删
|
||||
[deque](https://github.com/huihut/interview/tree/master/STL#deque)|双端队列(一个中央控制器+多个缓冲区)|无序|可重复|支持首尾快速增删,支持随机访问
|
||||
[stack](https://github.com/huihut/interview/tree/master/STL#stack)|deque 或 list 封闭头端开口|无序|可重复|不用 vector 的原因应该是容量大小有限制,扩容耗时
|
||||
[queue](https://github.com/huihut/interview/tree/master/STL#queue)|deque 或 list 封闭底端出口和前端入口|无序|可重复|不用 vector 的原因应该是容量大小有限制,扩容耗时
|
||||
[priority_queue](https://github.com/huihut/interview/tree/master/STL#priority_queue)|vector|无序|可重复|vector容器+heap处理规则
|
||||
[set](https://github.com/huihut/interview/tree/master/STL#set)|红黑树|有序|不可重复|
|
||||
[multiset](https://github.com/huihut/interview/tree/master/STL#multiset)|红黑树|有序|可重复|
|
||||
[map](https://github.com/huihut/interview/tree/master/STL#map)|红黑树|有序|不可重复|
|
||||
[multimap](https://github.com/huihut/interview/tree/master/STL#multimap)|红黑树|有序|可重复|
|
||||
hash_set|hash表|无序|不可重复|
|
||||
hash_multiset|hash表|无序|可重复|
|
||||
hash_map|hash表|无序|不可重复|
|
||||
hash_multimap|hash表|无序|可重复|
|
||||
容器 | 底层数据结构 | 时间复杂度 | 有无序 | 可不可重复 | 其他
|
||||
---|---|---|---|---|---
|
||||
[array](https://github.com/huihut/interview/tree/master/STL#array)|数组|随机读改 O(1)|无序|可重复|支持快速随机访问
|
||||
[vector](https://github.com/huihut/interview/tree/master/STL#vector)|数组|随机读改、尾部插入、尾部删除 O(1)<br/>头部插入、头部删除 O(n)|无序|可重复|支持快速随机访问
|
||||
[list](https://github.com/huihut/interview/tree/master/STL#list)|双向链表|插入、删除 O(1)<br/>随机读改 O(n)|无序|可重复|支持快速增删
|
||||
[deque](https://github.com/huihut/interview/tree/master/STL#deque)|双端队列|头尾插入、头尾删除 O(1)|无序|可重复|一个中央控制器 + 多个缓冲区,支持首尾快速增删,支持随机访问
|
||||
[stack](https://github.com/huihut/interview/tree/master/STL#stack)|deque / list|顶部插入、顶部删除 O(1)|无序|可重复|deque 或 list 封闭头端开口,不用 vector 的原因应该是容量大小有限制,扩容耗时
|
||||
[queue](https://github.com/huihut/interview/tree/master/STL#queue)|deque / list|尾部插入、头部删除 O(1)|无序|可重复|deque 或 list 封闭头端开口,不用 vector 的原因应该是容量大小有限制,扩容耗时
|
||||
[priority_queue](https://github.com/huihut/interview/tree/master/STL#priority_queue)|vector + max-heap|插入、删除 O(log<sub>2</sub>n)|有序|可重复|vector容器+heap处理规则
|
||||
[set](https://github.com/huihut/interview/tree/master/STL#set)|红黑树|插入、删除、查找 O(log<sub>2</sub>n)|有序|不可重复|
|
||||
[multiset](https://github.com/huihut/interview/tree/master/STL#multiset)|红黑树|插入、删除、查找 O(log<sub>2</sub>n)|有序|可重复|
|
||||
[map](https://github.com/huihut/interview/tree/master/STL#map)|红黑树|插入、删除、查找 O(log<sub>2</sub>n)|有序|不可重复|
|
||||
[multimap](https://github.com/huihut/interview/tree/master/STL#multimap)|红黑树|插入、删除、查找 O(log<sub>2</sub>n)|有序|可重复|
|
||||
hash_set|哈希表|插入、删除、查找 O(1) 最差 O(n)|无序|不可重复|
|
||||
hash_multiset|哈希表|插入、删除、查找 O(1) 最差 O(n)|无序|可重复|
|
||||
hash_map|哈希表|插入、删除、查找 O(1) 最差 O(n)|无序|不可重复|
|
||||
hash_multimap|哈希表|插入、删除、查找 O(1) 最差 O(n)|无序|可重复|
|
||||
|
||||
### STL 算法
|
||||
|
||||
算法 | 底层算法 | 时间复杂度 | 可不可重复
|
||||
---|---|---|---
|
||||
[find](http://www.cplusplus.com/reference/algorithm/find/)|顺序查找|O(n)|可重复
|
||||
[sort](https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/bits/stl_algo.h#L4808)|[内省排序](https://en.wikipedia.org/wiki/Introsort)|O(n*log<sub>2</sub>n)|可重复
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>〽️ 数据结构</summary></b>
|
||||
|
||||
## 数据结构
|
||||
|
||||
|
@ -1491,7 +1554,7 @@ typedef struct GLNode1 {
|
|||
4. 有 n 个结点的完全二叉树深度 k = ⌊ log<sub>2</sub>(n) ⌋ + 1
|
||||
5. 对于含 n 个结点的完全二叉树中编号为 i (1 <= i <= n) 的结点
|
||||
1. 若 i = 1,为根,否则双亲为 ⌊ i / 2 ⌋
|
||||
2. 若 2i > n,则 i 结点没有左孩子,否则孩子编号为 2i + 1
|
||||
2. 若 2i > n,则 i 结点没有左孩子,否则孩子编号为 2i
|
||||
3. 若 2i + 1 > n,则 i 结点没有右孩子,否则孩子编号为 2i + 1
|
||||
|
||||
#### 存储结构
|
||||
|
@ -1656,7 +1719,9 @@ typedef struct BiTNode
|
|||
* 三维计算机图形
|
||||
* 最邻近搜索
|
||||
|
||||
### 图
|
||||
</details>
|
||||
|
||||
<b><details><summary>⚡️ 算法</summary></b>
|
||||
|
||||
## 算法
|
||||
|
||||
|
@ -1668,8 +1733,8 @@ typedef struct BiTNode
|
|||
[选择排序](Algorithm/SelectionSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|数组不稳定、链表稳定
|
||||
[插入排序](Algorithm/InsertSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|稳定
|
||||
[快速排序](Algorithm/QuickSort.h) | O(n*log<sub>2</sub>n) | O(n<sup>2</sup>) | O(log<sub>2</sub>n) | 不稳定
|
||||
[堆排序](Algorithm/HeapSort.cpp) | O(n*log<sub>2</sub>n)|O(n<sup>2</sup>)|O(1)|不稳定
|
||||
[归并排序](Algorithm/MergeSort.h) | O(n*log<sub>2</sub>n) | O(n*log<sub>2</sub>n)|O(1)|稳定
|
||||
[堆排序](Algorithm/HeapSort.cpp) | O(n*log<sub>2</sub>n)|O(n*log<sub>2</sub>n)|O(1)|不稳定
|
||||
[归并排序](Algorithm/MergeSort.h) | O(n*log<sub>2</sub>n) | O(n*log<sub>2</sub>n)|O(n)|稳定
|
||||
[希尔排序](Algorithm/ShellSort.h) | O(n*log<sup>2</sup>n)|O(n<sup>2</sup>)|O(1)|不稳定
|
||||
[计数排序](Algorithm/CountSort.cpp) | O(n+m)|O(n+m)|O(n+m)|稳定
|
||||
[桶排序](Algorithm/BucketSort.cpp) | O(n)|O(n)|O(m)|稳定
|
||||
|
@ -1710,6 +1775,10 @@ B树/B+树 |O(log<sub>2</sub>n) | |
|
|||
[动态规划](https://zh.wikipedia.org/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92)|通过把原问题分解为相对简单的子问题的方式求解复杂问题的方法,适用于有重叠子问题和最优子结构性质的问题|[背包问题](https://github.com/huihut/interview/tree/master/Problems/KnapsackProblem)、斐波那契数列
|
||||
[贪心法](https://zh.wikipedia.org/wiki/%E8%B4%AA%E5%BF%83%E6%B3%95)|一种在每一步选择中都采取在当前状态下最好或最优(即最有利)的选择,从而希望导致结果是最好或最优的算法|旅行推销员问题(最短路径问题)、最小生成树、哈夫曼编码
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>❓ Problems</summary></b>
|
||||
|
||||
## Problems
|
||||
|
||||
### Single Problem
|
||||
|
@ -1739,6 +1808,10 @@ B树/B+树 |O(log<sub>2</sub>n) | |
|
|||
|
||||
* [牛客网 . 在线编程专题](https://www.nowcoder.com/activity/oj)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>💻 操作系统</summary></b>
|
||||
|
||||
## 操作系统
|
||||
|
||||
### 进程与线程
|
||||
|
@ -1976,6 +2049,10 @@ int main()
|
|||
* 最近最久未使用(LRU)算法
|
||||
* 时钟(Clock)置换算法
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>☁️ 计算机网络</summary></b>
|
||||
|
||||
## 计算机网络
|
||||
|
||||
计算机经网络体系结构:
|
||||
|
@ -2385,11 +2462,15 @@ TRACE | 回显服务器收到的请求,主要用于测试或诊断
|
|||
* 用于内部网络管理员作为对所有电脑作中央管理的手段
|
||||
* SNMP(Simple Network Management Protocol,简单网络管理协议)构成了互联网工程工作小组(IETF,Internet Engineering Task Force)定义的 Internet 协议族的一部分。该协议能够支持网络管理系统,用以监测连接到网络上的设备是否有任何引起管理上关注的情况。
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>🌩 网络编程</summary></b>
|
||||
|
||||
## 网络编程
|
||||
|
||||
### Socket
|
||||
|
||||
[Linux Socket 编程(不限 Linux)](https://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html)
|
||||
> [Linux Socket 编程(不限 Linux)](https://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html)
|
||||
|
||||
![Socket 客户端服务器通讯](images/socket客户端服务器通讯.jpg)
|
||||
|
||||
|
@ -2450,6 +2531,10 @@ ssize_t write(int fd, const void *buf, size_t count);
|
|||
|
||||
这样每个方向上都有一个 FIN 和 ACK。
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>💾 数据库</summary></b>
|
||||
|
||||
## 数据库
|
||||
|
||||
* 数据库事务四大特性:原子性、一致性、分离性、持久性
|
||||
|
@ -2465,6 +2550,10 @@ ssize_t write(int fd, const void *buf, size_t count);
|
|||
* 鲍依斯-科得范式(BCNF):满足 3NF,任何非主属性不能对主键子集依赖(消除 3NF 主属性对码的部分和传递函数依赖)
|
||||
* 第四范式(4NF):满足 3NF,属性之间不能有非平凡且非函数依赖的多值依赖(消除 3NF 非平凡且非函数依赖的多值依赖)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>📏 设计模式</summary></b>
|
||||
|
||||
## 设计模式
|
||||
|
||||
> 各大设计模式例子参考:[CSDN专栏 . C++ 设计模式](https://blog.csdn.net/column/details/15392.html) 系列博文
|
||||
|
@ -2500,6 +2589,10 @@ ssize_t write(int fd, const void *buf, size_t count);
|
|||
* 迪米特法则(LoD,Law of Demeter)
|
||||
* 开放封闭原则(OCP,Open Close Principle)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>⚙️ 链接装载库</summary></b>
|
||||
|
||||
## 链接装载库
|
||||
|
||||
### 内存、栈、堆
|
||||
|
@ -2894,11 +2987,11 @@ DUMPBIN -exports D:\mydll.dll
|
|||
|
||||
##### LoadLibrary
|
||||
|
||||
![WindowsLoadLibrary](http://ojlsgreog.bkt.clouddn.com/WindowsLoadLibrary.png)
|
||||
![WindowsLoadLibrary](images/WindowsLoadLibrary.png)
|
||||
|
||||
##### FreeLibrary
|
||||
|
||||
![WindowsFreeLibrary](http://ojlsgreog.bkt.clouddn.com/WindowsFreeLibrary.png)
|
||||
![WindowsFreeLibrary](images/WindowsFreeLibrary.png)
|
||||
|
||||
</details>
|
||||
|
||||
|
@ -3067,20 +3160,9 @@ int main( void )
|
|||
* 变长参数(stdarg.h)
|
||||
* 非局部跳转(setjmp.h)
|
||||
|
||||
## 海量数据处理
|
||||
</details>
|
||||
|
||||
* [ 海量数据处理面试题集锦](http://blog.csdn.net/v_july_v/article/details/6685962)
|
||||
* [十道海量数据处理面试题与十个方法大总结](http://blog.csdn.net/v_JULY_v/article/details/6279498)
|
||||
|
||||
## 音视频
|
||||
|
||||
* [最全实时音视频开发要用到的开源工程汇总](http://www.yunliaoim.com/im/1869.html)
|
||||
* [18个实时音视频开发中会用到开源项目](http://webrtc.org.cn/18%E4%B8%AA%E5%AE%9E%E6%97%B6%E9%9F%B3%E8%A7%86%E9%A2%91%E5%BC%80%E5%8F%91%E4%B8%AD%E4%BC%9A%E7%94%A8%E5%88%B0%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/)
|
||||
|
||||
## 其他
|
||||
|
||||
* [Bjarne Stroustrup 的常见问题](http://www.stroustrup.com/bs_faq.html)
|
||||
* [Bjarne Stroustrup 的 C++ 风格和技巧常见问题](http://www.stroustrup.com/bs_faq2.html)
|
||||
<b><details><summary>📚 书籍</summary></b>
|
||||
|
||||
## 书籍
|
||||
|
||||
|
@ -3114,44 +3196,69 @@ int main( void )
|
|||
|
||||
* 《程序员的自我修养》
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>💯 复习刷题网站</summary></b>
|
||||
|
||||
## 复习刷题网站
|
||||
|
||||
* [leetcode](https://leetcode.com/)
|
||||
* [牛客网](https://www.nowcoder.net/)
|
||||
* [慕课网](https://www.imooc.com/)
|
||||
* [菜鸟教程](http://www.runoob.com/)
|
||||
* [cplusplus](http://www.cplusplus.com/)
|
||||
* [cppreference](https://zh.cppreference.com/w/%E9%A6%96%E9%A1%B5)
|
||||
* [runoob](http://www.runoob.com/cplusplus/cpp-tutorial.html)
|
||||
* [leetcode](https://leetcode.com/) | [leetcode-cn](https://leetcode-cn.com/)
|
||||
* [lintcode](https://www.lintcode.com/)
|
||||
* [nowcoder](https://www.nowcoder.net/)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>📆 招聘时间岗位</summary></b>
|
||||
|
||||
## 招聘时间岗位
|
||||
|
||||
* [牛客网 . 2019 IT名企校招指南](https://www.nowcoder.com/activity/campus2019)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>📝 面试题目经验</summary></b>
|
||||
|
||||
## 面试题目经验
|
||||
|
||||
### 牛客网
|
||||
|
||||
* [牛客网 . 2019补招|互联网名企2019应届生补招专场合集](https://www.nowcoder.com/discuss/139360)
|
||||
* [牛客网 . 2019校招面经大汇总!【每日更新中】](https://www.nowcoder.com/discuss/90907)
|
||||
* [牛客网 . 2019校招技术类岗位面经汇总【技术类】](https://www.nowcoder.com/discuss/146655)
|
||||
* [牛客网 . 2018校招笔试真题汇总](https://www.nowcoder.com/discuss/68802)
|
||||
* [牛客网 . 2017秋季校园招聘笔经面经专题汇总](https://www.nowcoder.com/discuss/12805)
|
||||
* [牛客网 . 史上最全2017春招面经大合集!!](https://www.nowcoder.com/discuss/25268)
|
||||
* [牛客网 . 面试题干货在此](https://www.nowcoder.com/discuss/57978)
|
||||
|
||||
### 知乎
|
||||
|
||||
* [知乎 . 互联网求职路上,你见过哪些写得很好、很用心的面经?最好能分享自己的面经、心路历程。](https://www.zhihu.com/question/29693016)
|
||||
* [知乎 . 互联网公司最常见的面试算法题有哪些?](https://www.zhihu.com/question/24964987)
|
||||
* [知乎 . 面试 C++ 程序员,什么样的问题是好问题?](https://www.zhihu.com/question/20184857)
|
||||
|
||||
### CSDN
|
||||
|
||||
* [CSDN . 全面整理的C++面试题](http://blog.csdn.net/ljzcome/article/details/574158)
|
||||
* [CSDN . 百度研发类面试题(C++方向)](http://blog.csdn.net/Xiongchao99/article/details/74524807?locationNum=6&fps=1)
|
||||
* [CSDN . c++常见面试题30道](http://blog.csdn.net/fakine/article/details/51321544)
|
||||
* [CSDN . 腾讯2016实习生面试经验(已经拿到offer)](http://blog.csdn.net/onever_say_love/article/details/51223886)
|
||||
|
||||
### cnblogs
|
||||
|
||||
* [cnblogs . C++面试集锦( 面试被问到的问题 )](https://www.cnblogs.com/Y1Focus/p/6707121.html)
|
||||
* [cnblogs . C/C++ 笔试、面试题目大汇总](https://www.cnblogs.com/fangyukuan/archive/2010/09/18/1829871.html)
|
||||
* [cnblogs . 常见C++面试题及基本知识点总结(一)](https://www.cnblogs.com/LUO77/p/5771237.html)
|
||||
|
||||
### Segmentfault
|
||||
|
||||
* [segmentfault . C++常见面试问题总结](https://segmentfault.com/a/1190000003745529)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>👬 贡献者</summary></b>
|
||||
|
||||
## 贡献者
|
||||
|
||||
包括勘误的 Issue、PR,排序按照贡献时间。
|
||||
|
||||
[tamarous](https://github.com/tamarous)、[i0Ek3](https://github.com/i0Ek3)、[sniper00](https://github.com/sniper00)、[blackhorse001](https://github.com/blackhorse001)、[houbaron](https://github.com/houbaron)、[Qouan](https://github.com/Qouan)、[2329408386](https://github.com/2329408386)、[FlyingfishMORE](https://github.com/FlyingfishMORE)、[Ematrix163](https://github.com/Ematrix163)、[ReturnZero23](https://github.com/ReturnZero23)、[kelvinkuo](https://github.com/kelvinkuo)、[henryace](https://github.com/henryace)、[xinghun](https://github.com/xinghun)、[maokelong](https://github.com/maokelong)
|
||||
|
||||
</details>
|
||||
|
||||
<b><details><summary>📜 License</summary></b>
|
||||
|
||||
## License
|
||||
|
||||
本仓库不参与商业活动,遵循 CC BY-NC-SA 4.0(署名 - 非商业性使用) 协议,转载请注明出处。
|
||||
|
||||
[![CC BY-NC-SA 4.0](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)](LICENSE)
|
||||
|
||||
</details>
|
3211
README_Details.md
Normal file
3211
README_Details.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
images/GoogleCppStyleGuide.png
Normal file
BIN
images/GoogleCppStyleGuide.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 454 KiB |
BIN
images/WindowsFreeLibrary.png
Normal file
BIN
images/WindowsFreeLibrary.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 100 KiB |
BIN
images/WindowsLoadLibrary.png
Normal file
BIN
images/WindowsLoadLibrary.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
Loading…
Reference in New Issue
Block a user