Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

12.9.3 实例:链表

链表是最普通、最有用的数据结构之一。列表通常由一些“链接”组成,每个链接会保存一些信息和指向其他链接的指针。这是指针的典型用途之一。例如,一个挪威众神的短链表可图示如下:

一个像这样的链表被称为双向链表(doubly-linked list),对每个链接,我们都可以获得其前驱与后继。一个只能找到后继的列表被称为单向链表(singly-linked list)。当我们希望很容易地移除一个元素时,应使用双向链表。我们可以定义链接如下:

如果获得一个链接,我们可以使用succ指针到达它的后继,或者使用prev指针到达它的前驱。我们使用空指针来表示一个没有后继或前驱的链接。我们可以构造自己的挪威众神链表如下:

我们构建链表的方式是创建多个Link,并如图中所示将它们连接起来:首先是Thor,然后是Odin,它是Thor的前驱,最后是Freia,它是Odin的前驱。你可以沿着指针查看,我们构建了正确的链表,每个后继和前驱都指向正确的神。但是,这段代码有些混乱晦涩,因为我们没有明确地定义和命名插入操作。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252