1. Trang chủ
  2. » Giáo án - Bài giảng

Ch07 Queue.ppt

49 712 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

Cấu trúc

  • Chapter 7

  • Chapter Objectives

  • Queues

  • Slide 4

  • FIGURE 7.1 A conceptual view of a queue

  • Queue Operations

  • FIGURE 7.2 The operations on a queue

  • FIGURE 7.3 The QueueADT interface in UML

  • Listing 7.1

  • Coded Messages

  • Slide 11

  • FIGURE 7.4 An encoded message using a repeating key

  • Slide 13

  • Listing 7.2

  • Listing 7.2 (cont.)

  • FIGURE 7.5 UML description of the Codes program

  • Listing 7.3

  • Listing 7.3 (cont.)

  • Ticket Counter Simulation

  • Listing 7.4

  • Listing 7.4 (cont.)

  • Slide 22

  • FIGURE 7.6 UML description of the TicketCounter program

  • FIGURE 7.7 The results of the ticket counter simulation

  • Radix Sort

  • Slide 26

  • FIGURE 7.8 A radix sort of ten three-digit numbers

  • Listing 7.5

  • Listing 7.5 (cont.)

  • Slide 30

  • FIGURE 7.9 UML description of the RadixSort program

  • The LinkedQueue Class

  • FIGURE 7.10 A linked implementation of a queue

  • LinkedQueue - the enqueue Operation

  • FIGURE 7.11 The queue after adding element E

  • LinkedQueue - the dequeue Operation

  • FIGURE 7.12 The queue after a dequeue operation

  • The ArrayQueue Class

  • FIGURE 7.13 An array implementation of a queue

  • ArrayQueue - the enqueue Operation

  • FIGURE 7.14 The queue after adding element E

  • ArrayQueue - the dequeue Operation

  • FIGURE 7.15 The queue after removing the first element

  • The CircularArrayQueue Class

  • FIGURE 7.16 A circular array implementation of a queue

  • FIGURE 7.17 A queue straddling the end of a circular array

  • FIGURE 7.18 Changes in a circular array implementation of a queue

  • Circular Queues

  • Queue Implementations

Nội dung

Chapter 7 Queues Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2 Chapter Objectives • Examine queue processing • Define a queue abstract data type • Demonstrate how a queue can be used to solve problems • Examine various queue implementations • Compare queue implementations Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-3 Queues • A queue is a collection whose elements are added on one end and removed from another • Therefore a queue is processed in a FIFO fashion: first in, first out • Elements are removed in the same order they arrive • Any waiting line is a queue: – the check out line at a grocery store – the cars at a stop light – an assembly line Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-4 Queues • A queue is usually depicted horizontally • One end of the queue is the rear (or tail), where elements are added • The other end is the front (or head), from which elements are removed • Unlike a stack, which operates on one end of the collection, a queue operates on both ends Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-5 FIGURE 7.1 A conceptual view of a queue Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-6 Queue Operations • The term enqueue is used to refer to the process of adding an element to a queue • Likewise, dequeue is the process of removing an element • Like a stack, a pure queue does not allow the user to access the elements in the middle of the queue • We include a toString method for convenience Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-7 FIGURE 7.2 The operations on a queue Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-8 FIGURE 7.3 The QueueADT interface in UML Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-9 Listing 7.1 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-10 Coded Messages • Let's use a queue to help us encode and decode messages • A Ceasar cipher encodes a message by shifting each letter in a message by a constant amount k • If k is 5, A becomes F, B becomes G, etc. • However, this is fairly easy to break • An improvement can be made by changing how much a letter is shifted depending on where the letter is in the message . 7-6 Queue Operations • The term enqueue is used to refer to the process of adding an element to a queue • Likewise, dequeue is the process of removing an element • Like a stack, a pure queue. Messages • We'll use a queue to store the values of the key • We'll dequeue a value when needed • After using a key value, we then enqueue it back onto the end of the queue • That way the queue represents. Chapter 7 Queues Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2 Chapter Objectives • Examine queue processing • Define a queue abstract data type • Demonstrate how a queue can

Ngày đăng: 16/07/2014, 04:00

Xem thêm

TỪ KHÓA LIÊN QUAN

w