TAILIEUCHUNG - C++ for Mathematicians An Introduction for Students and Professionals phần 4

Phải có một và chỉ một xóa [] cân bằng mỗi lần sử dụng mới. Nếu xóa [] là mất tích, mảng vẫn còn cho đến khi chương trình thoát. Nếu có lặp đi lặp lại yêu cầu mới (mà không phù hợp với xóa [] s), sau đó nhiều bộ nhớ hơn và nhiều hơn nữa được gắn lên trong mảng | Containers 133 set long Union const set long A const set long B Inside the procedure we could build the union in a set named C and conclude with return C . Such a procedure would work but it would be inefficient. The problem is that the return variable would be copied to the calling procedure. We named the union procedure with a capital letter Union. Why not name this simply union The problem we are avoiding is that union is a C keyword not one that is of interest to mathematicians . We cannot name a procedure union just as we cannot name a procedure if or for. See Section if you are curious. These procedures work perfectly for sets of long integers but cannot be used for sets of double numbers. In C there is a mechanism to create a procedure schema called a template so that one procedure can be used with arguments of many different types. This is explained later in Chapter 12 . It is possible to initialize an iterator with methods other than begin and end. Another useful methodis find. If A is a set and e is an element then e returns an iterator for A that is focused on e. However if e is not in A then e signals its inability to find e in the set by returning that is an iterator that is one step beyond the end of the set. Multisets The directive include set also provides the multiset type. A multiset may contain an element repeatedly. For a set the count method returns only 0 or 1 for multisets it returns the multiplicity of the element and this may be any nonnegative integer. A multiset iterator is declared in the expected way multiset type iterator mi If an element appears several times in a set mi gives that value repeatedly as mi is increased. Here is an example. Program A program to demonstrate the use of multiset. 1 2 3 4 5 6 7 8 9 10 include iostream include set using namespace std int main multiset long A for int k 1 k 5 k k A - 1 2 3 4 5 3 we put an extra 3 into A 134 C for Mathematicians 11 12 13 14 15

TỪ KHÓA LIÊN QUAN
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.