TAILIEUCHUNG - Lecture Data visualization - Chapter 8

This chapter presents the following content: Data structures and problems with C, pointers, arrays and structures, types of arrays, use of vectors. | Lecture 08 Recap Data Structures and Problems with C Pointers Arrays and Structures Types of Arrays Use of Vectors Resizing the Vector One limitation of primitive arrays is that, once they have been declared, their size can never change However, we can use resize to change the size of a vector Pointers are used to give the illusion of an array that can be resized Example arr is representing a 10-element vector Somewhere, buried in the implementation then, memory is allocated for 10 elements Suppose that we would like to expand this memory to 12 elements The problem is that array elements must be stored in contiguous memory and that the memory immediately following arr might already be taken Continued . Do the following We remember where the memory for the 10-element array is (the purpose of original) We create a new 12-element array and have arr use it. We copy the 10 elements from original to arr; the two extra elements in the new arr have some default value We inform the system that the 10-element array can be reused as it sees fit Resizing Continued . Array expansion is implemented in some multiplicative constant times as large We might expand to make it twice as large When we expand the array from N items to 2N items, the cost of the N copies can be apportioned over the next N items that can be inserted into the array without an expansion this dynamic expansion is only negligibly more expensive than starting with a fixed size, but it is much more flexible push_back function The push-back function increases the size by one, and adds a new item into the array at the appropriate position This is a trivial operation if capacity has not been reached If it has, the capacity is automatically expanded, using the strategy described in previous topic Parameter-Passing Mechanism Three mechanism Call by Value Call by Reference Call by Constant Reference Call by Value Default parameter passing mechanism Natural declaration to pass a vector to a routine that finds the .

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.