1. Trang chủ
  2. » Luận Văn - Báo Cáo

Lecture 4_Set_Map_Hash.pptx

29 6 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Set, Map and Hash table Set, Map and Hash table University of Technology and Engineering Vietnam National University, Hanoi Set ➢A set is a collection of elements which are not in any particular order[.]

Set, Map and Hash table University of Technology and Engineering Vietnam National University, Hanoi Set ➢ A set is a collection of elements which are not in any particular order ➢ All elements of a set are different Set operations Set operations Union ➢ Definition: Let A and B be sets, the union of two sets A and B is the set that contains all elements in A, B, or both ➢ Example: A={0,1,3, 5,8} B= {2,5,8,9} A∪B = {0,1,2,3,5,8,9} Note: A∪B = B∪A Set operations Intersection ➢ Definition: Let A and B be sets, the intersection of two sets A and B is the set of elements that are in both A and B ➢ Example: A={1,2, 3,4,5} B= {1,3,9,12} A ∩B = {1,3} Note: A∩B = B∩A 12 5 Set operations Minus ➢ Definition: Let A and B be sets, the difference of A minus B (A – B) is the set of elements that are in A, but not in B ➢ Example: A={1,2,3} B= {2,3,4} A - B = {1} Using set library Unordered sets are containers that store unique elements in no particular order // unordered_set::insert #include #include #include #include int main () { std::unordered_set myset = {"yellow","green","blue"}; std::array myarray = {"black","white"}; std::string mystring = "red"; myset.insert (mystring); // copy insertion myset.insert (myarray.begin(), myarray.end()); // range insertion myset.insert ( {"purple","orange"} ); // initializer list insertion std::cout

Ngày đăng: 27/10/2023, 11:01

Xem thêm:

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN