1. Trang chủ
  2. » Cao đẳng - Đại học

Lecture Data structures and other objects using C++ - Chapter 5: Linked lists in action - Trường Đại học Công nghiệp Thực phẩm Tp. Hồ Chí Minh

10 15 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 622,47 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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]

Trang 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

Data Structures and Other Objects

Trang 2

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;

};

Trang 3

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;

   node *link_field;

};

Trang 4

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;

};

Trang 5

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

null

Trang 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

null

Trang 7

to the front of the linked list 

shown here

10

15

7 null

head_ptr entry

13

Trang 8

by a local variable insert_ptr

10

15

7

null

head_ptr entry

13

insert_ptr

Trang 9

insert_ptr = new node;

10

15

7

null

head_ptr entry

13

insert_ptr

Trang 10

15

7 null

head_ptr entry

13

insert_ptr

13

insert_ptr = new node;

Place the data in the new node's 

data_field

Ngày đăng: 01/04/2021, 03:05

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w