Computer-science_A-level_Cie
-
computers-and-components6 主题
-
logic-gates-and-logic-circuits2 主题
-
central-processing-unit-cpu-architecture6 主题
-
assembly-language-4 主题
-
bit-manipulation1 主题
-
operating-systems3 主题
-
language-translators2 主题
-
data-security3 主题
-
data-integrity1 主题
-
ethics-and-ownership3 主题
-
database-concepts3 主题
-
database-management-systems-dbms-1 主题
-
data-definition-language-ddl-and-data-manipulation-language-dml1 主题
-
computational-thinking-skills1 主题
-
algorithms14 主题
-
data-types-and-records2 主题
-
arrays2 主题
-
files1 主题
-
introduction-to-abstract-data-types-adt1 主题
-
programming-basics1 主题
-
constructs2 主题
-
structured-programming1 主题
-
program-development-life-cycle2 主题
-
program-design-2 主题
-
program-testing-and-maintenance3 主题
-
user-defined-data-types1 主题
-
file-organisation-and-access-3 主题
-
floating-point-numbers-representation-and-manipulation3 主题
-
protocols2 主题
-
circuit-switching-packet-switching1 主题
-
processors-parallel-processing-and-virtual-machines5 主题
-
boolean-algebra-and-logic-circuits4 主题
-
purposes-of-an-operating-system-os3 主题
-
translation-software3 主题
-
encryption-encryption-protocols-and-digital-certificates3 主题
-
artificial-intelligence-ai4 主题
-
recursion1 主题
-
programming-paradigms4 主题
-
object-oriented-programming7 主题
-
file-processing-and-exception-handling2 主题
-
data-representation5 主题
-
multimedia3 主题
-
compression2 主题
-
networks-and-the-internet11 主题
linked-lists
Linked lists
How do you program a linked list?
-
To recap the main operations of linked lists and how they work, read our ADT Overview page
-
To program a Linked List you must be able to perform the following operations:
-
Create a linked list
-
Traverse a linked list
-
Add data to a linked list
-
Remove data from a linked list
-
Create a linked list
-
Define the class called ‘Node’ that represents a node in the linked list.
-
Each node has 2 fields ‘fruit’ (this stores the fruit value) and ‘next’ (this stores a reference to the next node in the list)
-
We create 3 nodes and assign fruit values to each node
-
To establish a connection between the nodes we set the ‘next’ field of each node to the appropriate next node
|
Pseudocode |
|---|
|
|
Python |
|---|
|
|
Java |
|---|
|
Algorithm to traverse a linked list
-
We traverse the linked list starting from ‘node1’. We output the fruit value of each node and update the ‘current’ reference to the next node until we reach the end of the list
|
Pseudocode |
|---|
|
|
Python |
|---|
|
|
|
Java |
|---|
|
|
Algorithm to add data to a linked list
-
We create a new node with the new data and check if the list is empty
-
If it isn’t, we find the last node and add the new node to the end
|
Pseudocode |
|---|
|
|
Python |
|---|
|
|
|
Java |
|---|
|
|
Algorithm to remove data from a linked list
-
We traverse the list until we find the data to be removed
-
If the data to be removed is the first node, we update the head, else we update the node before to bypass the data to be removed
|
Pseudocode |
|---|
|
|
Python |
|---|
|
|
|
Java |
|---|
|
|
Worked Example
The following diagram represents an Abstract Data Type (ADT) for a linked list.
The free list is as follows:
Explain how a node containing data value B is added to the list in alphabetic sequence.[4]
Answer
One mark per point
-
Check for a free node [1 mark]
-
Search for correct insertion point [1 mark]
-
Assign data value B to first node in free list / node pointed to by start pointer of free list [1 mark]
-
Pointer from A will be changed to point to node containing B (instead of C) [1 mark]
-
Pointer from B will be changed to point to node containing C [1 mark]
-
Start pointer in free list moved to point to next free node [1 mark]
Responses