跳到主要内容

考纲要点

19.1.7 Linked List (Linear) ADT

What you must know

#PointExam Frequency
1Define a linked list as a collection of nodes where each node contains data and a pointer/reference to the next nodeLow
2Use a NODE record type with Data and NextPointer fieldsHigh
3Use a LinkedList record type with Head, Tail, CurrentPointer fieldsMedium
4Traverse a linked list and output dataHigh
5Insert a node at the start of a linked listMedium
6Insert a node at the end of a linked listHigh
7Insert a node into the middle of a linked listMedium
8Delete a node from a linked list (any position)High
9Understand free list / free pointer (Free / NextFree)Medium
10Implement search in a linked listMedium

What linked lists are used for

  • Dynamic memory allocation where size is not known in advance
  • Efficient insertion/deletion compared to arrays (no shifting)
  • Implementing queues, stacks, and other abstract data types

Linked list vs Array

OperationArrayLinked List
Access by indexO(1)O(n)
Insert at startO(n) — shift all elementsO(1) — update head pointer
Insert at endO(1) — if space availableO(1) — via tail pointer
DeleteO(n) — shift elementsO(n) — search then O(1) relink
MemoryContiguous, fixed sizeNon-contiguous, overhead per node

Typical setup in exam questions

// Global declarations
DECLARE Node : ARRAY[1:10] OF Node
DECLARE Head : INTEGER
DECLARE Tail : INTEGER
DECLARE Free : INTEGER

// Initialisation
Head ← -1
Tail ← -1
Free ← 1
FOR i ← 1 TO 9
Node[i].NextPointer ← i + 1
NEXT i
Node[10].NextPointer ← -1

Expected pseudocode constructs

ConstructExample
RecordTYPE Node ... ENDTYPE
Array of recordsDECLARE Node : ARRAY[1:10] OF Node
Field accessNode[Current].Data
AssignmentCurrent ← Node[Current].NextPointer
LoopWHILE Current <> -1
ConditionIF Head = -1 THEN
ProcedurePROCEDURE InsertNode(Value : INTEGER)
FunctionFUNCTION Search(Value : INTEGER) RETURNS INTEGER
备注

The exam expects pseudocode, not a specific programming language. Use for assignment, <> for not-equal, DECLARE for variable creation, and TYPE ... ENDTYPE for records.