Đang chuẩn bị liên kết để tải về tài liệu:
Data Structures and Algorithms in Java 4th phần 6

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Thời gian chạy của thuật toán này là gì? Trả lời Tập thể dục C-6,18 C 6,17 S giả định được thực hiện với một danh sách mảng. C-6,19 hoạt động hữu ích trong cơ sở dữ liệu là tham gia tự nhiên. Nếu chúng ta xem một cơ sở dữ liệu như là một danh sách các cặp đặt hàng của các đối tượng, | means of an unsorted or sorted list respectively. We assume that the list is implemented by a doubly linked list. The space requirement is O n . Method Unsorted List Sorted List size isEmpty O 1 O 1 insert O 1 O n min removeMin O n O 1 Java Implementation In Code Fragments 8.6 and 8.8 we show a Java implementation of a priority queue based on a sorted node list. This implementation uses a nested class called MyEntry to implement the Entry interface see Section 6.5.1 . We do not show auxiliary method checkKey k which throws an InvalidKeyException if key k cannot be compared with the comparator of the priority queue. Class DefaultComparator which realizes a comparator using the natural ordering is shown in Code Fragment 8.7. Code Fragment 8.6 Portions of the Java class SortedListPriorityQueue which implements the PriorityQueue interface. The nested class MyEntry implements the Entry interface. Continues in Code Fragment 8.8. 462 import java.util.Comparator Implementation of a priority queue by means of a sorted node list. public class SortedListPriorityQueue K V implements PriorityQueue K V I protected PositionList Entry K V entries protected Comparator K c protected PoSitiofi Entry K V actionPos variable used by subclasses Inner class for entries protected static class MyEntry K V implements Entry K V protected K k key protected V v value public My Ent n K key V value k key V - value methods of the Entry interface public K getKeyO return k public V getValuet return v Creates the priority queue with the default comparator. public SortedListPriorityQueue 0 entries new NodePositionList Entry K.V 0 0 new DefaultComparator K I Creates the priority queue with the given comparator. public Sorted Li st Priority Queue Comparator K comp entries new Nodeposition List Entry K V c comp Code Fragment 8.7 Java class Defaultcomparator that implements a comparator using the natural ordering and is the default comparator for class SortedListPriorityQueue. 463 Comparator based on the

Đã 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.