Map, set template [STL]

Source: Internet
Author: User

Set is used when you write a question word to search for it. In the evening, codeforces #497 div2 D is used for map.

I think the functions of set and map are quite similar. Here is a summary;

Here we will not specifically compare the similarities and differences, so as not to look messy. Here we will explain them separately;

 

Set:

# Include <set>

Set <...> S; (the type can be int, Char, string)

Functions:

Insert element; S. insert ()

Search element; S. Find ()

Delete element; S. Erase ()

Extract the beginning and end elements; set <int>: iterator itor; // This sentence must be written! Note!
Itor = S. Begin (); itor = S. End ();

Itor! = S. End (); can be used to determine whether an element is found

Set itself can define sorting;

Set <int, greater <int> S;

Set <int, less <int> S;

Insert or delete a single element, a range, or all, which can be customized;

I feel that a great god's blog is very detailed and I have learned it;

 

Map

Definition # include <map>

Map <...,...> F;

It can be int, Char, string

Because map is similar to hash, elements in map correspond to projection;

Here is an example: (See here)

When you need to store data in an integer array,

Ai-> I;

Map <int, int> B;

Simple write, which can be B [A [I] = I;

That is to say, the subscript in B [] and its corresponding value are both int;

Char also means the same

When you need to store B ['abc'] = 'defg';, you need to use Map <char, char> B;

 

Similar to set, map can insert elements, search for elements, and delete elements.

Insert can be simply written as B [A [I] =...

Search and delete are the same as set

 

 

The difference between map and set is better. Because map is closer to hash, the speed is much faster than set, but the set function is more complete than map.

Map, set template [STL]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.