1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Programming in C++ - Chapter 16: Data structures and recursion

21 71 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 309,57 KB

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

Nội dung

Lecture Programming in C++ - Chapter 16: Data structures and recursion. On completion of this chapter students will know how to: Create a linked list, create a stack, create a queue, create a binary tree, identify recursive functions.

Trang 1

and Recursion

Trang 5

node

Lesson 16.1

Trang 6

Use two classes to create linked list

– Node  class

Holds only the data All data members public because no function  members

– Second used to manipulate nodes

One variable holds address of first object in list Another variable holds current node address Lesson 16.1

Trang 7

       type member1;

       type member2;

       …       Node*  next_node;};

Trang 8

Address of node being manipulated Address of

first object

Trang 9

Data structure created using linked list modelWith stack can perform only two fundamental operations

Trang 10

Two classes create stack

– One class holds only data

Same form as linked list one member must be pointer variable

– Second class used to manipulate nodes

Data only pointer variables used to hold addresses 

of nodes Nodes of interest for stack are head and tail Function members initialize, push and pop items Lesson 16.2

Trang 11

Lesson 16.2

class Stack{

Trang 12

Create empty stack by initializing a head and tail node

Trang 13

Lesson 16.3

Trang 14

Lesson 16.3

class Queue {

      private:

      Node*  head;       Node*  tail;

      public:

      Queue ( );

      void insert (int);       int remov ( ); };

Trang 15

Dequeue ­ "double­ended queue"

– Nodes can be inserted at either end and removed  from either end

Trang 17

Nodes can also be called vertices or points

Connections between nodes called edges or arcs

Trang 18

– Rooted tree

Tree with one node specified to be root Root traditionally shown at top of diagram

– Binary tree

Tree in which no node has more than two children Lesson 16.4

Trang 19

       type  member;

       Tree_node*  left_child;        Tree_node* right_child; };

Trang 20

Within function body there is call to 

function with identical name and signatureBasic action which is repeated until it 

reaches the final iteration of the basic action

Lesson 16.5

Ngày đăng: 30/01/2020, 02:33

TỪ KHÓA LIÊN QUAN