deploy
@@ -12,20 +12,20 @@
|
||||
<meta name="author" content="Krahets">
|
||||
|
||||
|
||||
<link rel="canonical" href="https://www.hello-algo.com/chapter_data_structure/data_and_memory/">
|
||||
<link rel="canonical" href="https://www.hello-algo.com/chapter_data_structure/basic_data_types/">
|
||||
|
||||
|
||||
<link rel="prev" href="../../chapter_computational_complexity/summary/">
|
||||
<link rel="prev" href="../classification_of_data_structure/">
|
||||
|
||||
|
||||
<link rel="next" href="../classification_of_data_structure/">
|
||||
<link rel="next" href="../number_encoding/">
|
||||
|
||||
<link rel="icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.1.6">
|
||||
|
||||
|
||||
|
||||
<title>3.1. 基本数据类型 - Hello 算法</title>
|
||||
<title>3.2. 基本数据类型 - Hello 算法</title>
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#31" class="md-skip">
|
||||
<a href="#32" class="md-skip">
|
||||
跳转至
|
||||
</a>
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
3.1. 基本数据类型
|
||||
3.2. 基本数据类型
|
||||
|
||||
</span>
|
||||
</div>
|
||||
@@ -544,17 +544,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
|
||||
<label class="md-nav__title" for="__nav_4">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -562,6 +566,20 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../classification_of_data_structure/" class="md-nav__link">
|
||||
3.1. 数据结构分类
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -573,75 +591,10 @@
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
3.1. 基本数据类型
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<a href="./" class="md-nav__link md-nav__link--active">
|
||||
3.1. 基本数据类型
|
||||
3.2. 基本数据类型
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary" aria-label="目录">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
目录
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#311" class="md-nav__link">
|
||||
3.1.1. 基本数据类型
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="3.1.1. 基本数据类型">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_1" class="md-nav__link">
|
||||
整数表示方式
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_2" class="md-nav__link">
|
||||
浮点数表示方式 *
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_3" class="md-nav__link">
|
||||
基本数据类型与数据结构的关系
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#312" class="md-nav__link">
|
||||
3.1.2. 计算机内存
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@@ -653,8 +606,22 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../classification_of_data_structure/" class="md-nav__link">
|
||||
3.2. 数据结构分类
|
||||
<a href="../number_encoding/" class="md-nav__link">
|
||||
3.3. 数字编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../character_encoding/" class="md-nav__link">
|
||||
3.4. 字符编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -668,7 +635,7 @@
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../summary/" class="md-nav__link">
|
||||
3.3. 小结
|
||||
3.5. 小结
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -1849,55 +1816,6 @@
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
目录
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#311" class="md-nav__link">
|
||||
3.1.1. 基本数据类型
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="3.1.1. 基本数据类型">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_1" class="md-nav__link">
|
||||
整数表示方式
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_2" class="md-nav__link">
|
||||
浮点数表示方式 *
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#_3" class="md-nav__link">
|
||||
基本数据类型与数据结构的关系
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#312" class="md-nav__link">
|
||||
3.1.2. 计算机内存
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1911,7 +1829,7 @@
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/krahets/hello-algo/tree/main/docs/chapter_data_structure/data_and_memory.md" title="编辑此页" class="md-content__button md-icon">
|
||||
<a href="https://github.com/krahets/hello-algo/tree/main/docs/chapter_data_structure/basic_data_types.md" title="编辑此页" class="md-content__button md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10 20H6V4h7v5h5v3.1l2-2V8l-6-6H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h4v-2m10.2-7c.1 0 .3.1.4.2l1.3 1.3c.2.2.2.6 0 .8l-1 1-2.1-2.1 1-1c.1-.1.2-.2.4-.2m0 3.9L14.1 23H12v-2.1l6.1-6.1 2.1 2.1Z"/></svg>
|
||||
</a>
|
||||
@@ -1919,174 +1837,103 @@
|
||||
|
||||
|
||||
|
||||
<h1 id="31">3.1. 数据与内存<a class="headerlink" href="#31" title="Permanent link">¶</a></h1>
|
||||
<h2 id="311">3.1.1. 基本数据类型<a class="headerlink" href="#311" title="Permanent link">¶</a></h2>
|
||||
<h1 id="32">3.2. 基本数据类型<a class="headerlink" href="#32" title="Permanent link">¶</a></h1>
|
||||
<p>谈及计算机中的数据,我们会想到文本、图片、视频、语音、3D 模型等各种形式。尽管这些数据的组织形式各异,但它们都由各种基本数据类型构成。</p>
|
||||
<p><strong>「基本数据类型」是 CPU 可以直接进行运算的类型,在算法中直接被使用</strong>。</p>
|
||||
<p><strong>基本数据类型是 CPU 可以直接进行运算的类型,在算法中直接被使用</strong>。它包括:</p>
|
||||
<ul>
|
||||
<li>「整数」按照不同的长度分为 byte, short, int, long 。在满足取值范围的前提下,我们应该尽量选取较短的整数类型,以减小内存空间占用;</li>
|
||||
<li>「浮点数」表示小数,按长度分为 float, double ,选用规则与整数相同。</li>
|
||||
<li>「字符」在计算机中以字符集形式保存,char 的值实际上是数字,代表字符集中的编号,计算机通过字符集查表完成编号到字符的转换。</li>
|
||||
<li>「布尔」代表逻辑中的“是”与“否”,其占用空间需根据编程语言确定。</li>
|
||||
<li>整数类型 <code>byte</code> , <code>short</code> , <code>int</code> , <code>long</code> ;</li>
|
||||
<li>浮点数类型 <code>float</code> , <code>double</code> ,用于表示小数;</li>
|
||||
<li>字符类型 <code>char</code> ,用于表示各种语言的字母、标点符号、甚至表情符号等;</li>
|
||||
<li>布尔类型 <code>bool</code> ,用于表示“是”与“否”判断;</li>
|
||||
</ul>
|
||||
<p><strong>所有基本数据类型都以二进制的形式存储在计算机中</strong>。在计算机中,我们将 <span class="arithmatex">\(1\)</span> 个二进制位称为 <span class="arithmatex">\(1\)</span> 比特,并规定 <span class="arithmatex">\(1\)</span> 字节(byte)由 <span class="arithmatex">\(8\)</span> 比特(bits)组成。基本数据类型的取值范围取决于其占用的空间大小,例如:</p>
|
||||
<ul>
|
||||
<li>整数类型 <code>byte</code> 占用 <span class="arithmatex">\(1\)</span> byte = <span class="arithmatex">\(8\)</span> bits ,可以表示 <span class="arithmatex">\(2^{8}\)</span> 个不同的数字;</li>
|
||||
<li>整数类型 <code>int</code> 占用 <span class="arithmatex">\(4\)</span> bytes = <span class="arithmatex">\(32\)</span> bits ,可以表示 <span class="arithmatex">\(2^{32}\)</span> 个数字;</li>
|
||||
</ul>
|
||||
<p>下表列举了各种基本数据类型的占用空间、取值范围和默认值。此表格无需硬背,大致理解即可,需要时可以通过查表来回忆。</p>
|
||||
<div class="center-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>类别</th>
|
||||
<th>类型</th>
|
||||
<th>符号</th>
|
||||
<th>占用空间</th>
|
||||
<th>取值范围</th>
|
||||
<th>最小值</th>
|
||||
<th>最大值</th>
|
||||
<th>默认值</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>整数</td>
|
||||
<td>byte</td>
|
||||
<td><code>byte</code></td>
|
||||
<td>1 byte</td>
|
||||
<td><span class="arithmatex">\(-2^7\)</span> ~ <span class="arithmatex">\(2^7 - 1\)</span> ( <span class="arithmatex">\(-128\)</span> ~ <span class="arithmatex">\(127\)</span> )</td>
|
||||
<td><span class="arithmatex">\(-2^7\)</span> (<span class="arithmatex">\(-128\)</span>)</td>
|
||||
<td><span class="arithmatex">\(2^7 - 1\)</span> (<span class="arithmatex">\(127\)</span>)</td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>short</td>
|
||||
<td><code>short</code></td>
|
||||
<td>2 bytes</td>
|
||||
<td><span class="arithmatex">\(-2^{15}\)</span> ~ <span class="arithmatex">\(2^{15} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(-2^{15}\)</span></td>
|
||||
<td><span class="arithmatex">\(2^{15} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><strong>int</strong></td>
|
||||
<td><code>int</code></td>
|
||||
<td>4 bytes</td>
|
||||
<td><span class="arithmatex">\(-2^{31}\)</span> ~ <span class="arithmatex">\(2^{31} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(-2^{31}\)</span></td>
|
||||
<td><span class="arithmatex">\(2^{31} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>long</td>
|
||||
<td><code>long</code></td>
|
||||
<td>8 bytes</td>
|
||||
<td><span class="arithmatex">\(-2^{63}\)</span> ~ <span class="arithmatex">\(2^{63} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(-2^{63}\)</span></td>
|
||||
<td><span class="arithmatex">\(2^{63} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>浮点数</td>
|
||||
<td><strong>float</strong></td>
|
||||
<td><code>float</code></td>
|
||||
<td>4 bytes</td>
|
||||
<td><span class="arithmatex">\(-3.4 \times 10^{38}\)</span> ~ <span class="arithmatex">\(3.4 \times 10^{38}\)</span></td>
|
||||
<td><span class="arithmatex">\(0.0\)</span> f</td>
|
||||
<td><span class="arithmatex">\(1.175 \times 10^{-38}\)</span></td>
|
||||
<td><span class="arithmatex">\(3.403 \times 10^{38}\)</span></td>
|
||||
<td><span class="arithmatex">\(0.0 f\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>double</td>
|
||||
<td><code>double</code></td>
|
||||
<td>8 bytes</td>
|
||||
<td><span class="arithmatex">\(-1.7 \times 10^{308}\)</span> ~ <span class="arithmatex">\(1.7 \times 10^{308}\)</span></td>
|
||||
<td><span class="arithmatex">\(2.225 \times 10^{-308}\)</span></td>
|
||||
<td><span class="arithmatex">\(1.798 \times 10^{308}\)</span></td>
|
||||
<td><span class="arithmatex">\(0.0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>字符</td>
|
||||
<td><strong>char</strong></td>
|
||||
<td><code>char</code></td>
|
||||
<td>2 bytes / 1 byte</td>
|
||||
<td><span class="arithmatex">\(0\)</span> ~ <span class="arithmatex">\(2^{16} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
<td><span class="arithmatex">\(2^{16} - 1\)</span></td>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>布尔</td>
|
||||
<td><strong>bool</strong></td>
|
||||
<td><code>bool</code></td>
|
||||
<td>1 byte / 1 bit</td>
|
||||
<td><span class="arithmatex">\(\text{true}\)</span> 或 <span class="arithmatex">\(\text{false}\)</span></td>
|
||||
<td><span class="arithmatex">\(\text{false}\)</span></td>
|
||||
<td><span class="arithmatex">\(\text{true}\)</span></td>
|
||||
<td><span class="arithmatex">\(\text{false}\)</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>以上表格中,加粗项在算法题中最为常用。此表格无需硬背,大致理解即可,需要时可以通过查表来回忆。</p>
|
||||
<h3 id="_1">整数表示方式<a class="headerlink" href="#_1" title="Permanent link">¶</a></h3>
|
||||
<p>整数的取值范围取决于变量使用的内存长度,即字节(或比特)数。在计算机中,1 字节 (byte) = 8 比特 (bit),1 比特即 1 个二进制位。以 int 类型为例:</p>
|
||||
<ol>
|
||||
<li>整数类型 int 占用 4 bytes = 32 bits ,可以表示 <span class="arithmatex">\(2^{32}\)</span> 个不同的数字;</li>
|
||||
<li>将最高位视为符号位,<span class="arithmatex">\(0\)</span> 代表正数,<span class="arithmatex">\(1\)</span> 代表负数,一共可表示 <span class="arithmatex">\(2^{31}\)</span> 个正数和 <span class="arithmatex">\(2^{31}\)</span> 个负数;</li>
|
||||
<li>当所有 bits 为 0 时代表数字 <span class="arithmatex">\(0\)</span> ,从零开始增大,可得最大正数为 <span class="arithmatex">\(2^{31} - 1\)</span> ;</li>
|
||||
<li>剩余 <span class="arithmatex">\(2^{31}\)</span> 个数字全部用来表示负数,因此最小负数为 <span class="arithmatex">\(-2^{31}\)</span> ;具体细节涉及“源码、反码、补码”的相关知识,有兴趣的同学可以查阅学习;</li>
|
||||
</ol>
|
||||
<p>其他整数类型 byte, short, long 的取值范围的计算方法与 int 类似,在此不再赘述。</p>
|
||||
<h3 id="_2">浮点数表示方式 *<a class="headerlink" href="#_2" title="Permanent link">¶</a></h3>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>本书中,标题后的 * 符号代表选读章节。如果你觉得理解困难,建议先跳过,等学完必读章节后再单独攻克。</p>
|
||||
</div>
|
||||
<p>细心的你可能会发现:int 和 float 长度相同,都是 4 bytes,但为什么 float 的取值范围远大于 int ?按理说 float 需要表示小数,取值范围应该变小才对。</p>
|
||||
<p>实际上,这是因为浮点数 float 采用了不同的表示方式。根据 IEEE 754 标准,32-bit 长度的 float 由以下部分构成:</p>
|
||||
<ul>
|
||||
<li>符号位 <span class="arithmatex">\(\mathrm{S}\)</span> :占 1 bit ;</li>
|
||||
<li>指数位 <span class="arithmatex">\(\mathrm{E}\)</span> :占 8 bits ;</li>
|
||||
<li>分数位 <span class="arithmatex">\(\mathrm{N}\)</span> :占 24 bits ,其中 23 位显式存储;</li>
|
||||
</ul>
|
||||
<p>设 32-bit 二进制数的第 <span class="arithmatex">\(i\)</span> 位为 <span class="arithmatex">\(b_i\)</span> ,则 float 值的计算方法定义为:</p>
|
||||
<div class="arithmatex">\[
|
||||
\text { val } = (-1)^{b_{31}} \times 2^{\left(b_{30} b_{29} \ldots b_{23}\right)_2-127} \times\left(1 . b_{22} b_{21} \ldots b_0\right)_2
|
||||
\]</div>
|
||||
<p>转化到十进制下的计算公式为</p>
|
||||
<div class="arithmatex">\[
|
||||
\text { val }=(-1)^{\mathrm{S}} \times 2^{\mathrm{E} -127} \times (1 + \mathrm{N})
|
||||
\]</div>
|
||||
<p>其中各项的取值范围为</p>
|
||||
<div class="arithmatex">\[
|
||||
\begin{aligned}
|
||||
\mathrm{S} \in & \{ 0, 1\} , \quad \mathrm{E} \in \{ 1, 2, \dots, 254 \} \newline
|
||||
(1 + \mathrm{N}) = & (1 + \sum_{i=1}^{23} b_{23-i} 2^{-i}) \subset [1, 2 - 2^{-23}]
|
||||
\end{aligned}
|
||||
\]</div>
|
||||
<p><img alt="IEEE 754 标准下的 float 表示方式" src="../data_and_memory.assets/ieee_754_float.png" /></p>
|
||||
<p align="center"> Fig. IEEE 754 标准下的 float 表示方式 </p>
|
||||
|
||||
<p>以上图为例,<span class="arithmatex">\(\mathrm{S} = 0\)</span> , <span class="arithmatex">\(\mathrm{E} = 124\)</span> ,<span class="arithmatex">\(\mathrm{N} = 2^{-2} + 2^{-3} = 0.375\)</span> ,易得</p>
|
||||
<div class="arithmatex">\[
|
||||
\text { val } = (-1)^0 \times 2^{124 - 127} \times (1 + 0.375) = 0.171875
|
||||
\]</div>
|
||||
<p>现在我们可以回答最初的问题:<strong>float 的表示方式包含指数位,导致其取值范围远大于 int</strong> 。根据以上计算,float 可表示的最大正数为 <span class="arithmatex">\(2^{254 - 127} \times (2 - 2^{-23}) \approx 3.4 \times 10^{38}\)</span> ,切换符号位便可得到最小负数。</p>
|
||||
<p><strong>尽管浮点数 float 扩展了取值范围,但其副作用是牺牲了精度</strong>。整数类型 int 将全部 32 位用于表示数字,数字是均匀分布的;而由于指数位的存在,浮点数 float 的数值越大,相邻两个数字之间的差值就会趋向越大。</p>
|
||||
<p>进一步地,指数位 <span class="arithmatex">\(E = 0\)</span> 和 <span class="arithmatex">\(E = 255\)</span> 具有特殊含义,<strong>用于表示零、无穷大、<span class="arithmatex">\(\mathrm{NaN}\)</span> 等</strong>。</p>
|
||||
<div class="center-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>指数位 E</th>
|
||||
<th>分数位 <span class="arithmatex">\(\mathrm{N} = 0\)</span></th>
|
||||
<th>分数位 <span class="arithmatex">\(\mathrm{N} \ne 0\)</span></th>
|
||||
<th>计算公式</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><span class="arithmatex">\(0\)</span></td>
|
||||
<td><span class="arithmatex">\(\pm 0\)</span></td>
|
||||
<td>次正规数</td>
|
||||
<td><span class="arithmatex">\((-1)^{\mathrm{S}} \times 2^{-126} \times (0.\mathrm{N})\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class="arithmatex">\(1, 2, \dots, 254\)</span></td>
|
||||
<td>正规数</td>
|
||||
<td>正规数</td>
|
||||
<td><span class="arithmatex">\((-1)^{\mathrm{S}} \times 2^{(\mathrm{E} -127)} \times (1.\mathrm{N})\)</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class="arithmatex">\(255\)</span></td>
|
||||
<td><span class="arithmatex">\(\pm \infty\)</span></td>
|
||||
<td><span class="arithmatex">\(\mathrm{NaN}\)</span></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p>特别地,次正规数显著提升了浮点数的精度,这是因为:</p>
|
||||
<ul>
|
||||
<li>最小正正规数为 <span class="arithmatex">\(2^{-126} \approx 1.18 \times 10^{-38}\)</span> ;</li>
|
||||
<li>最小正次正规数为 <span class="arithmatex">\(2^{-126} \times 2^{-23} \approx 1.4 \times 10^{-45}\)</span> ;</li>
|
||||
</ul>
|
||||
<p>双精度 double 也采用类似 float 的表示方法,此处不再详述。</p>
|
||||
<h3 id="_3">基本数据类型与数据结构的关系<a class="headerlink" href="#_3" title="Permanent link">¶</a></h3>
|
||||
<p>我们知道,<strong>数据结构是在计算机中组织与存储数据的方式</strong>,它的核心是“结构”,而非“数据”。如果想要表示“一排数字”,我们自然会想到使用「数组」数据结构。数组的存储方式可以表示数字的相邻关系、顺序关系,但至于具体存储的是整数 int 、小数 float 、还是字符 char ,则与“数据结构”无关。换句话说,基本数据类型提供了数据的“内容类型”,而数据结构提供了数据的“组织方式”。</p>
|
||||
<p>那么,基本数据类型与数据结构之间有什么联系与区别呢?我们知道,数据结构是在计算机中组织与存储数据的方式。它的主语是“结构”,而非“数据”。如果想要表示“一排数字”,我们自然会想到使用数组。这是因为数组的线性结构可以表示数字的相邻关系和顺序关系,但至于存储的内容是整数 <code>int</code> 、小数 <code>float</code> 、还是字符 <code>char</code> ,则与“数据结构”无关。</p>
|
||||
<p>换句话说,<strong>基本数据类型提供了数据的“内容类型”,而数据结构提供了数据的“组织方式”</strong>。如以下代码所示,我们可以使用不同基本数据类型来初始化数组。</p>
|
||||
<div class="tabbed-set tabbed-alternate" data-tabs="1:10"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Java</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Python</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">JavaScript</label><label for="__tabbed_1_6">TypeScript</label><label for="__tabbed_1_7">C</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">Swift</label><label for="__tabbed_1_10">Zig</label></div>
|
||||
<div class="tabbed-content">
|
||||
<div class="tabbed-block">
|
||||
@@ -2160,14 +2007,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 id="312">3.1.2. 计算机内存<a class="headerlink" href="#312" title="Permanent link">¶</a></h2>
|
||||
<p>在计算机中,内存和硬盘是两种主要的存储硬件设备。「硬盘」主要用于长期存储数据,容量较大(通常可达到 TB 级别)、速度较慢。「内存」用于运行程序时暂存数据,速度较快,但容量较小(通常为 GB 级别)。</p>
|
||||
<p><strong>在算法运行过程中,相关数据都存储在内存中</strong>。下图展示了一个计算机内存条,其中每个黑色方块都包含一块内存空间。我们可以将内存想象成一个巨大的 Excel 表格,其中每个单元格都可以存储 1 byte 的数据,在算法运行时,所有数据都被存储在这些单元格中。</p>
|
||||
<p><strong>系统通过「内存地址 Memory Location」来访问目标内存位置的数据</strong>。计算机根据特定规则为表格中的每个单元格分配编号,确保每个内存空间都有唯一的内存地址。有了这些地址,程序便可以访问内存中的数据。</p>
|
||||
<p><img alt="内存条、内存空间、内存地址" src="../data_and_memory.assets/computer_memory_location.png" /></p>
|
||||
<p align="center"> Fig. 内存条、内存空间、内存地址 </p>
|
||||
|
||||
<p><strong>在数据结构与算法的设计中,内存资源是一个重要的考虑因素</strong>。内存是所有程序的共享资源,当内存被某个程序占用时,其他程序无法同时使用。我们需要根据剩余内存资源的实际情况来设计算法。例如,算法所占用的内存峰值不应超过系统剩余空闲内存;如果运行的程序很多并且缺少大量连续的内存空间,那么所选用的数据结构必须能够存储在离散的内存空间内。</p>
|
||||
|
||||
|
||||
|
||||
@@ -2245,7 +2084,7 @@
|
||||
<nav class="md-footer__inner md-grid" aria-label="页脚" >
|
||||
|
||||
|
||||
<a href="../../chapter_computational_complexity/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 2.4. &nbsp; 小结" rel="prev">
|
||||
<a href="../classification_of_data_structure/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 3.1. &nbsp; 数据结构分类" rel="prev">
|
||||
<div class="md-footer__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||
</div>
|
||||
@@ -2254,20 +2093,20 @@
|
||||
上一页
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
2.4. 小结
|
||||
3.1. 数据结构分类
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="../classification_of_data_structure/" class="md-footer__link md-footer__link--next" aria-label="下一页: 3.2. &nbsp; 数据结构分类" rel="next">
|
||||
<a href="../number_encoding/" class="md-footer__link md-footer__link--next" aria-label="下一页: 3.3. &nbsp; 数字编码 *" rel="next">
|
||||
<div class="md-footer__title">
|
||||
<span class="md-footer__direction">
|
||||
下一页
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
3.2. 数据结构分类
|
||||
3.3. 数字编码 *
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
BIN
chapter_data_structure/character_encoding.assets/ascii_table.png
Normal file
|
After Width: | Height: | Size: 193 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 73 KiB |
2171
chapter_data_structure/character_encoding/index.html
Normal file
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 212 KiB |
@@ -15,17 +15,17 @@
|
||||
<link rel="canonical" href="https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/">
|
||||
|
||||
|
||||
<link rel="prev" href="../data_and_memory/">
|
||||
<link rel="prev" href="../../chapter_computational_complexity/summary/">
|
||||
|
||||
|
||||
<link rel="next" href="../summary/">
|
||||
<link rel="next" href="../basic_data_types/">
|
||||
|
||||
<link rel="icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.1.6">
|
||||
|
||||
|
||||
|
||||
<title>3.2. 数据结构分类 - Hello 算法</title>
|
||||
<title>3.1. 数据结构分类 - Hello 算法</title>
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#32" class="md-skip">
|
||||
<a href="#31" class="md-skip">
|
||||
跳转至
|
||||
</a>
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
3.2. 数据结构分类
|
||||
3.1. 数据结构分类
|
||||
|
||||
</span>
|
||||
</div>
|
||||
@@ -544,17 +544,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
|
||||
<label class="md-nav__title" for="__nav_4">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -562,20 +566,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../data_and_memory/" class="md-nav__link">
|
||||
3.1. 基本数据类型
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -588,12 +578,12 @@
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
3.2. 数据结构分类
|
||||
3.1. 数据结构分类
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<a href="./" class="md-nav__link md-nav__link--active">
|
||||
3.2. 数据结构分类
|
||||
3.1. 数据结构分类
|
||||
</a>
|
||||
|
||||
|
||||
@@ -612,15 +602,15 @@
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#321" class="md-nav__link">
|
||||
3.2.1. 逻辑结构:线性与非线性
|
||||
<a href="#311" class="md-nav__link">
|
||||
3.1.1. 逻辑结构:线性与非线性
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#322" class="md-nav__link">
|
||||
3.2.2. 物理结构:连续与离散
|
||||
<a href="#312" class="md-nav__link">
|
||||
3.1.2. 物理结构:连续与离散
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@@ -639,9 +629,51 @@
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../basic_data_types/" class="md-nav__link">
|
||||
3.2. 基本数据类型
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../number_encoding/" class="md-nav__link">
|
||||
3.3. 数字编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../character_encoding/" class="md-nav__link">
|
||||
3.4. 字符编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../summary/" class="md-nav__link">
|
||||
3.3. 小结
|
||||
3.5. 小结
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -1829,15 +1861,15 @@
|
||||
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#321" class="md-nav__link">
|
||||
3.2.1. 逻辑结构:线性与非线性
|
||||
<a href="#311" class="md-nav__link">
|
||||
3.1.1. 逻辑结构:线性与非线性
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#322" class="md-nav__link">
|
||||
3.2.2. 物理结构:连续与离散
|
||||
<a href="#312" class="md-nav__link">
|
||||
3.1.2. 物理结构:连续与离散
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@@ -1865,9 +1897,9 @@
|
||||
|
||||
|
||||
|
||||
<h1 id="32">3.2. 数据结构分类<a class="headerlink" href="#32" title="Permanent link">¶</a></h1>
|
||||
<h1 id="31">3.1. 数据结构分类<a class="headerlink" href="#31" title="Permanent link">¶</a></h1>
|
||||
<p>数据结构可以从逻辑结构和物理结构两个维度进行分类。</p>
|
||||
<h2 id="321">3.2.1. 逻辑结构:线性与非线性<a class="headerlink" href="#321" title="Permanent link">¶</a></h2>
|
||||
<h2 id="311">3.1.1. 逻辑结构:线性与非线性<a class="headerlink" href="#311" title="Permanent link">¶</a></h2>
|
||||
<p><strong>「逻辑结构」揭示了数据元素之间的逻辑关系</strong>。在数组和链表中,数据按照顺序依次排列,体现了数据之间的线性关系;而在树中,数据从顶部向下按层次排列,表现出祖先与后代之间的派生关系;图则由节点和边构成,反映了复杂的网络关系。</p>
|
||||
<p>逻辑结构通常分为「线性」和「非线性」两类。线性结构比较直观,指数据在逻辑关系上呈线性排列;非线性结构则相反,呈非线性排列,例如网状或树状结构。</p>
|
||||
<ul>
|
||||
@@ -1877,12 +1909,15 @@
|
||||
<p><img alt="线性与非线性数据结构" src="../classification_of_data_structure.assets/classification_logic_structure.png" /></p>
|
||||
<p align="center"> Fig. 线性与非线性数据结构 </p>
|
||||
|
||||
<h2 id="322">3.2.2. 物理结构:连续与离散<a class="headerlink" href="#322" title="Permanent link">¶</a></h2>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>如若阅读起来有困难,建议先阅读下一章“数组与链表”,然后再回头理解物理结构的含义。</p>
|
||||
</div>
|
||||
<p><strong>「物理结构」体现了数据在计算机内存中的存储方式</strong>,可以分为数组的连续空间存储和链表的离散空间存储。物理结构从底层决定了数据的访问、更新、增删等操作方法,同时在时间效率和空间效率方面呈现出互补的特点。</p>
|
||||
<h2 id="312">3.1.2. 物理结构:连续与离散<a class="headerlink" href="#312" title="Permanent link">¶</a></h2>
|
||||
<p>在计算机中,内存和硬盘是两种主要的存储硬件设备。「硬盘」主要用于长期存储数据,容量较大(通常可达到 TB 级别)、速度较慢。「内存」用于运行程序时暂存数据,速度较快,但容量较小(通常为 GB 级别)。</p>
|
||||
<p><strong>在算法运行过程中,相关数据都存储在内存中</strong>。下图展示了一个计算机内存条,其中每个黑色方块都包含一块内存空间。我们可以将内存想象成一个巨大的 Excel 表格,其中每个单元格都可以存储 1 byte 的数据,在算法运行时,所有数据都被存储在这些单元格中。</p>
|
||||
<p><strong>系统通过「内存地址 Memory Location」来访问目标内存位置的数据</strong>。计算机根据特定规则为表格中的每个单元格分配编号,确保每个内存空间都有唯一的内存地址。有了这些地址,程序便可以访问内存中的数据。</p>
|
||||
<p><img alt="内存条、内存空间、内存地址" src="../classification_of_data_structure.assets/computer_memory_location.png" /></p>
|
||||
<p align="center"> Fig. 内存条、内存空间、内存地址 </p>
|
||||
|
||||
<p>内存是所有程序的共享资源,当内存被某个程序占用时,其他程序无法同时使用。<strong>因此,在数据结构与算法的设计中,内存资源是一个重要的考虑因素</strong>。例如,算法所占用的内存峰值不应超过系统剩余空闲内存;如果运行的程序很多并且缺少大量连续的内存空间,那么所选用的数据结构必须能够存储在离散的内存空间内。</p>
|
||||
<p><strong>「物理结构」反映了数据在计算机内存中的存储方式</strong>,可分为数组的连续空间存储和链表的离散空间存储。物理结构从底层决定了数据的访问、更新、增删等操作方法,同时在时间效率和空间效率方面呈现出互补的特点。</p>
|
||||
<p><img alt="连续空间存储与离散空间存储" src="../classification_of_data_structure.assets/classification_phisical_structure.png" /></p>
|
||||
<p align="center"> Fig. 连续空间存储与离散空间存储 </p>
|
||||
|
||||
@@ -1894,7 +1929,7 @@
|
||||
<p>基于数组实现的数据结构也被称为「静态数据结构」,这意味着此类数据结构在初始化后长度不可变。相对应地,基于链表实现的数据结构被称为「动态数据结构」,这类数据结构在初始化后,仍可以在程序运行过程中对其长度进行调整。</p>
|
||||
<div class="admonition tip">
|
||||
<p class="admonition-title">Tip</p>
|
||||
<p>数组与链表是其他所有数据结构的“底层积木”,建议读者投入更多时间深入了解这两种基本数据结构。</p>
|
||||
<p>如若感觉理解物理结构有困难,建议先阅读下一章“数组与链表”,然后再回头理解物理结构的含义。数组与链表是其他所有数据结构的基石,建议你投入更多时间深入了解这两种基本数据结构。</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1973,7 +2008,7 @@
|
||||
<nav class="md-footer__inner md-grid" aria-label="页脚" >
|
||||
|
||||
|
||||
<a href="../data_and_memory/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 3.1. &nbsp; 基本数据类型" rel="prev">
|
||||
<a href="../../chapter_computational_complexity/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 2.4. &nbsp; 小结" rel="prev">
|
||||
<div class="md-footer__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||
</div>
|
||||
@@ -1982,20 +2017,20 @@
|
||||
上一页
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
3.1. 基本数据类型
|
||||
2.4. 小结
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 3.3. &nbsp; 小结" rel="next">
|
||||
<a href="../basic_data_types/" class="md-footer__link md-footer__link--next" aria-label="下一页: 3.2. &nbsp; 基本数据类型" rel="next">
|
||||
<div class="md-footer__title">
|
||||
<span class="md-footer__direction">
|
||||
下一页
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
3.3. 小结
|
||||
3.2. 基本数据类型
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
|
Before Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 63 KiB |
BIN
chapter_data_structure/number_encoding.assets/ieee_754_float.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
2217
chapter_data_structure/number_encoding/index.html
Normal file
@@ -15,7 +15,7 @@
|
||||
<link rel="canonical" href="https://www.hello-algo.com/chapter_data_structure/summary/">
|
||||
|
||||
|
||||
<link rel="prev" href="../classification_of_data_structure/">
|
||||
<link rel="prev" href="../character_encoding/">
|
||||
|
||||
|
||||
<link rel="next" href="../../chapter_array_and_linkedlist/array/">
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
|
||||
<title>3.3. 小结 - Hello 算法</title>
|
||||
<title>3.5. 小结 - Hello 算法</title>
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#33" class="md-skip">
|
||||
<a href="#35" class="md-skip">
|
||||
跳转至
|
||||
</a>
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
3.3. 小结
|
||||
3.5. 小结
|
||||
|
||||
</span>
|
||||
</div>
|
||||
@@ -544,17 +544,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
</label>
|
||||
|
||||
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
|
||||
<label class="md-nav__title" for="__nav_4">
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
3. 数据结构简介
|
||||
3. 数据结构与数据
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
@@ -564,8 +568,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../data_and_memory/" class="md-nav__link">
|
||||
3.1. 基本数据类型
|
||||
<a href="../classification_of_data_structure/" class="md-nav__link">
|
||||
3.1. 数据结构分类
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -578,8 +582,36 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../classification_of_data_structure/" class="md-nav__link">
|
||||
3.2. 数据结构分类
|
||||
<a href="../basic_data_types/" class="md-nav__link">
|
||||
3.2. 基本数据类型
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../number_encoding/" class="md-nav__link">
|
||||
3.3. 数字编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../character_encoding/" class="md-nav__link">
|
||||
3.4. 字符编码 *
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -602,7 +634,7 @@
|
||||
|
||||
|
||||
<a href="./" class="md-nav__link md-nav__link--active">
|
||||
3.3. 小结
|
||||
3.5. 小结
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@@ -1805,13 +1837,20 @@
|
||||
|
||||
|
||||
|
||||
<h1 id="33">3.3. 小结<a class="headerlink" href="#33" title="Permanent link">¶</a></h1>
|
||||
<h1 id="35">3.5. 小结<a class="headerlink" href="#35" title="Permanent link">¶</a></h1>
|
||||
<ul>
|
||||
<li>计算机中的基本数据类型包括整数 byte, short, int, long 、浮点数 float, double 、字符 char 和布尔 boolean ,它们的取值范围取决于占用空间大小和表示方式。</li>
|
||||
<li>当程序运行时,数据被存储在计算机内存中。每个内存空间都拥有对应的内存地址,程序通过这些内存地址访问数据。</li>
|
||||
<li>数据结构可以从逻辑结构和物理结构两个角度进行分类。逻辑结构描述了数据元素之间的逻辑关系,而物理结构描述了数据在计算机内存中的存储方式。</li>
|
||||
<li>常见的逻辑结构包括线性、树状和网状等。通常我们根据逻辑结构将数据结构分为线性(数组、链表、栈、队列)和非线性(树、图、堆)两种。哈希表的实现可能同时包含线性和非线性结构。</li>
|
||||
<li>当程序运行时,数据被存储在计算机内存中。每个内存空间都拥有对应的内存地址,程序通过这些内存地址访问数据。</li>
|
||||
<li>物理结构主要分为连续空间存储(数组)和离散空间存储(链表)。所有数据结构都是由数组、链表或两者的组合实现的。</li>
|
||||
<li>计算机中的基本数据类型包括整数 byte, short, int, long 、浮点数 float, double 、字符 char 和布尔 boolean 。它们的取值范围取决于占用空间大小和表示方式。</li>
|
||||
<li>整数的原码的最高位是符号位,其余位是数字的值。数字的原码、反码和补码是可以相互转换的。</li>
|
||||
<li>整数在计算机中是以补码的形式存储的。在补码表示下,计算机可以对正数和负数的加法一视同仁,不需要为减法操作单独设计特殊的硬件电路,并且不存在正负零歧义的问题。</li>
|
||||
<li>浮点数的编码由 1 位符号位、8 位指数位和 23 位分数为构成。由于存在指数位,浮点数的取值范围远大于整数。</li>
|
||||
<li>ASCII 码是最早出现的英文字符集,长度为 1 字节,共收录 127 个字符。GBK 字符集是常用的中文字符集,共收录两万多个汉字。</li>
|
||||
<li>Unicode 致力于提供一个统一的字符集标准,其包含世界范围内的各种字符,从而解决由于字符编码不同导致的乱码问题。</li>
|
||||
<li>UTF-8 是最受欢迎的 Unicode 编码方法,通用性非常好。它是一种变长的编码方法,具有很好的扩展性,有效提升了存储空间的使用效率。</li>
|
||||
<li>UTF-16 和 UTF-32 是等长的编码方法。在编码中文时,UTF-16 比 UTF-8 的占用空间更小。Java, C# 等编程语言默认使用 UTF-16 编码。</li>
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -1890,7 +1929,7 @@
|
||||
<nav class="md-footer__inner md-grid" aria-label="页脚" >
|
||||
|
||||
|
||||
<a href="../classification_of_data_structure/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 3.2. &nbsp; 数据结构分类" rel="prev">
|
||||
<a href="../character_encoding/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 3.4. &nbsp; 字符编码 *" rel="prev">
|
||||
<div class="md-footer__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||
</div>
|
||||
@@ -1899,7 +1938,7 @@
|
||||
上一页
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
3.2. 数据结构分类
|
||||
3.4. 字符编码 *
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||