TAILIEUCHUNG - Lecture Data structures and algorithms in Java (6th edition): Chapter 6 - Goodrich, Tamassia, Goldwasser

This chapter provides knowledge of queues. Data structures and algorithms in java provides an introduction to data structures and algorithms, including their design, analysis, and implementation. | Queues 3/16/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues 1 The Queue ADT q   q   q   q   The Queue ADT stores arbitrary q   objects Insertions and deletions follow the first-in first-out scheme Insertions are at the rear of the queue and removals are at the front of the queue Main queue operations: n   n   enqueue(object): inserts an element at the end of the q   queue object dequeue(): removes and returns the element at the front of the queue © 2014 Goodrich, Tamassia, Goldwasser Queues Auxiliary queue operations: n   n   n   object first(): returns the element at the front without removing it integer size(): returns the number of elements stored boolean isEmpty(): indicates whether no elements are stored Boundary cases: n   Attempting the execution of dequeue or first on an empty queue returns null 2 1 Queues 3/16/14 Example Operation enqueue(5) enqueue(3) dequeue() enqueue(7) dequeue() first() dequeue() dequeue() isEmpty() enqueue(9) enqueue(7) size() enqueue(3) enqueue(5) dequeue() © 2014 Goodrich, Tamassia, Goldwasser – – 5 – 3 7 7 null true – – 2 – – 9 Output Q (5) (5, 3) (3) (3, 7) (7) (7) () () () (9) (9, 7) (9, 7) (9, 7, 3) (9, 7, 3, 5) (7, 3, 5) Queues 3 Applications of Queues q   Direct applications Waiting lists, bureaucracy n   Access to shared resources (., printer) n   Multiprogramming n   q   Indirect applications Auxiliary data structure for algorithms n   Component of other data structures n   © 2014 Goodrich, Tamassia, Goldwasser Queues 4 2 Queues 3/16/14 Array-based Queue q   q   Use an array of size N in a circular fashion Two variables keep track of the front and size f index of the front element sz number of stored elements q   When the queue has fewer than N elements, array location r = (f + sz) mod N is the first .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.