Java software solutions foundations of program design 4th edition phần 8

Một mảng là chỉ có một cách thức mà một danh sách có thể được đại diện. Mảng được giới hạn trong một ý nghĩa bởi vì họ có một kích thước cố định trong suốt sự tồn tại của họ. Đôi khi chúng ta không biết lớn như thế nào để làm cho một mảng | representing data structures 639 representing data structures An array is only one way in which a list can be represented. Arrays are limited in one sense because they have a fixed size throughout their existence. Sometimes we don t know how big to make an array because we don t know how much information we will store. The ArrayList class handles this by creating a larger array and copying everything over whenever necessary. This is not necessarily an efficient implementation. A dynamic data structure is implemented using links. Using references as links between objects we can create whatever type of structure is appropriate for the situation. If implemented carefully the structure can be quite efficient to search and modify. Structures created this way are considered to be dynamic because their size is determined dynamically as they are used and not by their declaration. A fixed data structure has a specific size for the duration of its existence whereas a dynamic data structure grows and shrinks as needed. dynamic structures Recall from Chapter 4 that all objects are created dynamically using the new operator. A variable used to keep track of an object is actually a reference to the object meaning that it stores the address of the object. Recall that a declaration such as House home new House 602 Greenbriar Court actually accomplishes two things it declares home to be a reference to a House object and it instantiates an object of class House. Now consider an object that contains a reference to another object of the same type. For example class Node int info Node next Two objects of this class can be instantiated and chained together by having the next reference of one Node object refer to the other Node object. The second object s next reference can refer to a third Node object and so on creating a linked list. The first node in the list could A dynamically linked list is managed by storing and updating references to objects. be referenced using a .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.