From 713b7f7d3089c9e8a7bda87460bd3880878f57f2 Mon Sep 17 00:00:00 2001 From: Utkarsh-Singhal-26 Date: Sun, 18 Jan 2026 12:07:21 +0530 Subject: [PATCH 1/2] [Term Entry] Dart Queue: .addFirst() --- .../concepts/queue/terms/addFirst/addFirst.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 content/dart/concepts/queue/terms/addFirst/addFirst.md diff --git a/content/dart/concepts/queue/terms/addFirst/addFirst.md b/content/dart/concepts/queue/terms/addFirst/addFirst.md new file mode 100644 index 00000000000..6849dcd3c10 --- /dev/null +++ b/content/dart/concepts/queue/terms/addFirst/addFirst.md @@ -0,0 +1,58 @@ +git--- +Title: '.addFirst()' +Description: 'Adds an element at the beginning of a queue.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Dart' + - 'Queues' + - 'Methods' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **`.addFirst()`** method adds an element at the beginning of a `Queue`. This method is part of the `Queue` class under the `dart:collection` library. + +## Syntax +```pseudo +queue.addFirst(element); +``` + +**Parameters:** + +- `element`: The element to be added at the beginning of the queue. + +**Return value:** + +This method does not return a value. + +## Example + +The following example demonstrates the usage of the `.addFirst()` method: +```dart +import 'dart:collection'; + +void main() { + Queue numbers = Queue(); + numbers.add(20); + numbers.add(30); + numbers.add(40); + + print("Original queue: $numbers"); + + numbers.addFirst(10); + print("After addFirst(10): $numbers"); + + numbers.addFirst(5); + print("After addFirst(5): $numbers"); +} +``` + +The output for the above code is as follows: +```shell +Original queue: {20, 30, 40} +After addFirst(10): {10, 20, 30, 40} +After addFirst(5): {5, 10, 20, 30, 40} +``` \ No newline at end of file From c3552ff6a796ec12adb4095ada976f40438e2f94 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 20 Jan 2026 19:48:22 +0530 Subject: [PATCH 2/2] Clarify .addFirst() method description and usage Updated the description to clarify the behavior of the .addFirst() method and made minor adjustments to the syntax and example sections. --- .../dart/concepts/queue/terms/addFirst/addFirst.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/content/dart/concepts/queue/terms/addFirst/addFirst.md b/content/dart/concepts/queue/terms/addFirst/addFirst.md index 6849dcd3c10..741d2b8a5ed 100644 --- a/content/dart/concepts/queue/terms/addFirst/addFirst.md +++ b/content/dart/concepts/queue/terms/addFirst/addFirst.md @@ -1,4 +1,4 @@ -git--- +--- Title: '.addFirst()' Description: 'Adds an element at the beginning of a queue.' Subjects: @@ -13,24 +13,26 @@ CatalogContent: - 'paths/computer-science' --- -In Dart, the **`.addFirst()`** method adds an element at the beginning of a `Queue`. This method is part of the `Queue` class under the `dart:collection` library. +In Dart, the **`.addFirst()`** method inserts an element at the front of a `Queue`. Existing elements are shifted back, and the newly added element becomes the first item in the queue. This method is part of the `Queue` class under the `dart:collection` library. ## Syntax + ```pseudo queue.addFirst(element); ``` **Parameters:** -- `element`: The element to be added at the beginning of the queue. +- `element`: The element to add to the front of the queue **Return value:** -This method does not return a value. +This method does not return a value (`void`). ## Example The following example demonstrates the usage of the `.addFirst()` method: + ```dart import 'dart:collection'; @@ -51,8 +53,9 @@ void main() { ``` The output for the above code is as follows: + ```shell Original queue: {20, 30, 40} After addFirst(10): {10, 20, 30, 40} After addFirst(5): {5, 10, 20, 30, 40} -``` \ No newline at end of file +```