Skip to content

Commit fc73a88

Browse files
Refine swap() method documentation in unordered_set
Updated wording for clarity and consistency in the swap method documentation.
1 parent e45c046 commit fc73a88

File tree

1 file changed

+11
-11
lines changed
  • content/cpp/concepts/unordered-set/terms/swap

1 file changed

+11
-11
lines changed

content/cpp/concepts/unordered-set/terms/swap/swap.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ CatalogContent:
1313
- 'paths/computer-science'
1414
---
1515

16-
The **`swap()`** method exchanges the contents of one [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set) with another. This operation runs in constant time because it swaps internal structures rather than moving individual elements.
16+
The **`swap()`** method exchanges the contents of one [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set) with another. This operation runs in constant time by swapping internal structures rather than moving individual elements.
1717

1818
After the swap, both containers take ownership of each other's elements. Iterators and references remain valid but now refer to elements stored in the opposite container.
1919

20-
The two unordered sets need not have the same size but should have the same template parameters.
20+
The two `unordered_set` containers do not need to have the same size, but they must be of the same type.
2121

2222
## Syntax
2323

24-
The `swap()` method can be used with the following syntax:
24+
The `swap()` method can be used in the following syntax:
2525

26-
1. Member Function
26+
1/. Member Function
2727

2828
```pseudo
2929
unordered_set_first.swap(unordered_set_second);
3030
```
3131

32-
1. Non-Member Function
32+
2/. Non-Member Function
3333

3434
```pseudo
3535
swap(unordered_set_first, unordered_set_second);
@@ -39,12 +39,13 @@ swap(unordered_set_first, unordered_set_second);
3939

4040
- `unordered_set_second`: Another `unordered_set` with the same template parameters(element type, hash, predicate, allocator) as `unordered_set_first`.
4141

42-
**Return Value:**
42+
**Return value:**
43+
4344
This method returns nothing (`void`).
4445

4546
## Example
4647

47-
This example demonstrates swapping contents between two `unordered_set` containers:
48+
In this example, the contents of two `unordered_set` containers are exchanged using the member `swap()` function:
4849

4950
```cpp
5051
#include <iostream>
@@ -77,22 +78,22 @@ int main() {
7778

7879
return 0;
7980
}
80-
8181
```
8282

8383
The expected output of this code is:
8484

85-
```
85+
```shell
8686
Before swap:
8787
setA contents: 3 2 1
8888
setB contents: 20 10
8989

9090
After swap:
9191
setA contents: 20 10
9292
setB contents: 3 2 1
93-
9493
```
9594

95+
> **Note:** The output order may vary because `unordered_set` does not maintain a defined element order.
96+
9697
## Codebyte Example
9798

9899
In this example, the code swaps the contents of two `unordered_set` containers and prints their updated elements:
@@ -128,5 +129,4 @@ int main() {
128129
129130
return 0;
130131
}
131-
132132
```

0 commit comments

Comments
 (0)