| |

VerySource

 Forgot password?
 Register
Search
View: 959|Reply: 9

set comparison

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-11 11:20:01
| Show all posts |Read mode
The two sets, set1, set2 all store 10,000 long data. Is there a fast way to determine that the values ​​stored in the two sets are the same? Is the value of set1 in set2, and the value of set2 All in set1?
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-15 16:18:01
| Show all posts
Sort the two SETs in the way you want, and then scan from the first to the last, and see if the values ​​corresponding to the first sequence numbers are equal to indicate whether the two SETs are the same.
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-15 16:54:01
| Show all posts
Your method is a regular method, and its complexity is 0 (x)
Reply

Use magic Report

1

Threads

27

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-15 20:36:01
| Show all posts
Sorting-> Compare with serial number
Reply

Use magic Report

0

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-17 13:54:01
| Show all posts
The set itself is ordered, get an iterator to traverse, and directly compare by sequence number.
Reply

Use magic Report

0

Threads

41

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 France

Post time: 2020-1-17 15:27:01
| Show all posts
It is orderly in itself, just compare them one by one.
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-17 17:27:02
| Show all posts
For set, set1 == set2 directly
Requires data types and sorting criteria to be the same
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-1-17 18:00:01
| Show all posts
For details, please refer to Chapter 6 Section 5 of the C ++ Standard Library
Reply

Use magic Report

0

Threads

18

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-19 17:45:01
| Show all posts
Agree one by one.
Reply

Use magic Report

0

Threads

24

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-5 12:45:01
| Show all posts
Isn't it sufficient to compare the two sets directly?

Asfiregunsaid, "the data type and sorting criteria must be the same."
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list