diff --git a/content/cpp/concepts/unordered-set/terms/end/end.md b/content/cpp/concepts/unordered-set/terms/end/end.md new file mode 100644 index 00000000000..5d2994a3b29 --- /dev/null +++ b/content/cpp/concepts/unordered-set/terms/end/end.md @@ -0,0 +1,102 @@ +--- +Title: 'end()' +Description: 'Returns an iterator pointing just past the last element of the unordered set, marking the end of the container’s range.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Iterators' + - 'Sets' + - 'STL' +CatalogContent: + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +The **`end()`** method returns an iterator that points to the past-the-end position of an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set). This iterator marks one past the last element and cannot be dereferenced. Because `unordered_set` does not maintain a defined order, iteration proceeds in the container’s internal hash-table order. + +## Syntax + +```pseudo +unordered_set_name.end(); +``` + +**Parameters:** + +The `end()` function takes no parameters. + +**Return value:** + +Returns an `iterator` pointing to the past-the-end position of the `unordered_set`. + +Or, to work with a specific bucket: + +```pseudo +unordered_set_name.end(n); +``` + +**Parameters:** + +- `n` (size_type): The bucket index. Must be less than `bucket_count()`. + +**Return value:** + +A `local_iterator` pointing to the past-the-end position in bucket `n`. If the bucket is empty, `begin(n) == end(n)`. + +## Example + +In this example, iteration runs from `begin()` to `end()` to print every element in the `unordered_set`: + +```cpp +#include +#include +using namespace std; + +int main() { + unordered_set unique_numbers = {10, 5, 20, 15}; + + for (auto it = unique_numbers.begin(); it != unique_numbers.end(); ++it) { + cout << *it << "\n"; + } + + return 0; +} +``` + +A sample output might be: + +```shell +20 +5 +10 +15 +``` + +> **Note:** The output order may vary because `unordered_set` does not store elements in any defined sequence. + +## Codebyte Example + +This example retrieves iterators for a specific bucket in the `unordered_set` and prints all elements stored in that bucket: + +```codebyte/cpp +#include +#include +using namespace std; + +int main() { + unordered_set words = {"cat", "dog", "rabbit", "lion"}; + + size_t bucket = 0; + + auto it = words.begin(bucket); + auto last = words.end(bucket); + + cout << "Elements in bucket " << bucket << ":\n"; + + for (; it != last; ++it) { + cout << " " << *it << "\n"; + } + + return 0; +} +``` diff --git a/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md b/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md deleted file mode 100644 index 9d1e2157596..00000000000 --- a/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -Title: '.querySelectorAll()' -Description: 'Returns a static (non-live) NodeList of all elements in the document that match the given CSS selectors.' -Subjects: - - 'Code Foundations' - - 'Web Development' -Tags: - - 'Methods' - - 'Node' - - 'Selectors' -CatalogContent: - - 'introduction-to-javascript' - - 'paths/front-end-engineer-career-path' ---- - -In JavaScript, the **`.querySelectorAll()`** method under the `document` object returns a static (not live) `NodeList` of all elements that match the given group of [selectors](https://www.codecademy.com/resources/docs/css/selectors). - -## Syntax - -```pseudo -document.querySelectorAll(selectors); -``` - -- `selectors`: Represents a string containing one or more CSS selectors used to match elements in the document. It follows the same rules as CSS selectors and can include: - - Type selectors (`div`, `p`, `span`) - - Class selectors (`.class-name`) - - ID selectors (`#id-name`) - - Attribute selectors (`[type="text"]`, `[disabled]`) - - Combinations (`div p`, `.container > p`, `ul > li:first-child`) - -## Examples - -### Example 1 - -In this example, a `NodeList` of all `

` elements in the document is obtained: - -```js -const matches = document.querySelectorAll('p'); -``` - -### Example 2 - -The following example returns a list of all `

` elements in the document with a class of either `note` or `alert`: - -```js -const matches = document.querySelectorAll('div.note, div.alert'); -``` - -### Example 3 - -In this example, a list of `

` elements is obtained, whose immediate parent is a `

` with the class `highlighted`, and which are inside a container with the ID `test`: - -```js -const container = document.querySelector('#test'); -const matches = container.querySelectorAll('div.highlighted > p'); -```