A program can keep track of the front node by using a pointer variable such as head_ptr in this example. Notice that head_ptr is not a node it is a pointer to a node[r]
(1)Chapter 5 introduces the often used data structure of linked lists This presentation shows how to implement the most common operations on linked lists
CHAPTER 5
(2)For this presentation, nodes in a
linked list are objects, as shown here
data_field link_field
10
data_field link_field
15
data_field link_field
7
null
class node {
public:
typedef double value_type;
private
value_type data_field; node *link_field;
(3)The data_field of each node is a type called
value_type, defined by a typedef
data_field
link_field
10
data_field
link_field
15
data_field
link_field
7
null
class node {
public:
typedef int value_type;
private
value_type data_field;
(4)Each node also contains a link_field which is a pointer to another node
data_field
link_field 10
data_field
link_field 15
data_field
link_field 7
null class node
{
public:
typedef int value_type;
private
value_type data_field; node *link_field;
(5)A program can keep track of the front node by using a pointer variable such as head_ptr in this example
Notice that head_ptr is not a node it is a pointer to a node
head_ptr
data_field link_field
10
data_field link_field
15
data_field link_field
7
(6)A program can keep track of the front node by using a pointer variable such as head_ptr
Notice that head_ptr is not a node it is a pointer to a node
We represent the empty list by storing
null in the head pointer
head_ptr
(7)We want to add a new entry, 13,
We want to add a new entry, 13,
to the
to the frontfront of the linked list of the linked list shown here
shown here
10
15
7 null
head_ptr entry
(8)Create a new node, pointed to by a local variable insert_ptr
10
15
7 7
null
head_ptr entry
13
(9)insert_ptr = new node;
10
15
7 7 null
head_ptr entry
13
(10)10
15
7 null
head_ptr entry
13
insert_ptr
13
insert_ptr = new node;