🗂️ 数据结构:数据怎么摆🗂️ Data Structure: How Data Is Laid Out
上一片,小电脑把榨汁步骤打包成了函数。可生意越来越好:盘子、顾客、文件,堆成了山。乱放就难找。这一片,学会给数据摆好位置。Last leaf, the little computer packed its juice steps into a function. But business is booming: plates, customers and files pile up. Messy piles are hard to search. This leaf teaches how to give data a proper place.
第 1 步:一摞盘子——栈Step 1: A pile of plates — the stack
数据一多,怎么摆才好拿?With lots of data, how should it be laid out?
先认识数据结构:数据的摆放方式。最简单的是数组:一排编号格子。栈像一摞盘子。新盘子放顶上,取也先取顶上。这叫后进先出。撤销键就是栈:最后一步最先撤。Meet the data structure: a way to lay data out. The simplest is the array: a row of numbered slots. A stack is a pile of plates. New plates go on top, and the top comes off first. That is last in, first out. Undo is a stack: the last step is undone first.
可顾客排队时,能让最后来的先拿吗?But in a line of customers, should the last one go first?
第 2 步:排好队——队列Step 2: Waiting in line — the queue
不行,那得用队列。队列就像排队买果汁。从队尾加入,从队头离开。先到先得,也叫先进先出。打印机排任务,游戏排房间,都靠队列。No — that needs a queue. A queue is a line for juice. Join at the back, leave from the front. First come, first served: first in, first out. Printer jobs and game matchmaking both wait in queues.
数据分了上下级,一排排放不下,怎么办?What if data has levels that rows can’t hold?
第 3 步:分层放——树Step 3: Levels — the tree
用树!一个根文件夹,分出子文件夹,再分出文件。你电脑里的文件夹,就是一棵树。顺着树枝往下找,几步就到。网页、家谱、目录,也都是树。Use a tree! One root folder splits into sub-folders, then into files. The folders on your computer form a tree. Follow the branches down and you arrive in a few steps. Web pages, family trees and contents pages are trees too.
🎮 你来摆订单(30 秒)🎮 Your turn: store the orders (30 seconds)
道理讲完了。再添一位字典:报名字直接翻到。先把 4 张订单放进四种结构,再接 4 关:给场景挑结构。Theory done. Meet one more: the dictionary, which jumps straight to a name. First put 4 orders into four structures, then take 4 rounds: pick the right structure for each scene.
一句话记住它:数据结构 = 数据的摆放方式;摆法决定谁先出来、找得多快。Remember it in one line: a data structure = how data is laid out; the layout decides who comes out first and how fast you find things.
栈后进先出(盘子),队列先进先出(排队)Stack: last in, first out (plates); queue: first in, first out (a line)数组按编号拿,字典按名字找,一步到位Array grabs by number, dictionary finds by name — one step树一层层分下去:文件夹就是树A tree splits level by level: folders are a tree
内容参考 OpenStax 等公开教材,多来源核对 · AI 生成、人工审核 · 发现错误欢迎指正,帮这片叶子长得更好。Based on OpenStax and other open textbooks, cross-checked across sources · AI-generated, human-reviewed · Spotted a mistake? Tell us — help this leaf grow.