> For the complete documentation index, see [llms.txt](https://ksmcclay.gitbook.io/no-code-computer-science/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ksmcclay.gitbook.io/no-code-computer-science/data-structures/untitled.md).

# Array

An Array is an ordered collection of elements

## What is an Array? :first\_place: :second\_place: :third\_place:&#x20;

An **Array** is an ordered collection of elements.

![Row of Mailboxes](https://3642656209-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLGBprg9M6rsaEbC96_%2F-MMD_nOlhye0tDuhY3o2%2F-MMDaG9vr4IaQKW2HQML%2Ftimothy-eberly-1mPBkYvbu3w-unsplash.jpg?alt=media\&token=40ed5bef-67e7-434d-aa91-6e9daa9a793a)

## A Row of Mailboxes:mailbox\_closed::mailbox\_closed::mailbox\_closed:

To access, obtain, add, or remove mail (an item) from the row of mailboxes (**array**),  the only information needed is the number to the mailbox.

## 1 dimensional :page\_facing\_up: , 2 dimensional :closed\_book: , 3 dimensional :books:&#x20;

An **array** can be 1D, 2D, 3D, and beyond.

* *1D **Array***&#x20;
  * *a row of mailboxes (left/right)*
  * :mailbox\_closed::mailbox\_closed::mailbox\_closed:
* *2D **Array***&#x20;
  * *Multiple rows of mailboxes (left/right & up/down)*
  * :mailbox\_closed::mailbox\_closed::mailbox\_closed:
  * :mailbox\_closed::mailbox\_closed::mailbox\_closed:
  * :mailbox\_closed::mailbox\_closed::mailbox\_closed:
* *3D **Array***
  * *multiple columns of multiple rows of multiple mailboxes (left/right & up/down & forward/backward)*
  * :mailbox\_closed::mailbox\_closed:     :mailbox\_closed::mailbox\_closed:     :mailbox\_closed::mailbox\_closed:
  * :mailbox\_closed::mailbox\_closed:     :mailbox\_closed::mailbox\_closed:     :mailbox\_closed::mailbox\_closed:      &#x20;

## Stacks and Queues:apple: :tangerine:&#x20;

**Stacks** and **queues** are examples of 1D **arrays.**&#x20;

## Stacks :pancakes::dango::hamburger:&#x20;

The stack is exactly as it sounds, items stacked on top of each other. Adding and removing items always occur with top of the stack.

![Stack](https://3642656209-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLGBprg9M6rsaEbC96_%2F-MLe-sBNrzV6EExW-uT9%2F-MLePA0FOnHkJnkgSEzb%2Fpexels-markus-spiske-95218.jpg?alt=media\&token=444cd39b-2b81-44c5-949f-b623c0d80624)

The vertical **array** utilizes the L.I.F.O. (Last In First Out) principal, which is the last item to go in the stack is the first item to get out of the stack.

* Removal -> top of the stack
* Adding    -> top of the stack&#x20;
* Example: pringles, dishes, zen rock stacking

## **Queues** :fries: :person\_walking: :woman\_walking: :man\_walking:

The **Queue** is the same as a line. Adding items occurs at the beginning of the queue and removing items occurs at the end of the queue.

![Queue](https://3642656209-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLGBprg9M6rsaEbC96_%2F-MLe-sBNrzV6EExW-uT9%2F-MLeRKRySW3Pz1YyWux1%2Fpexels-nat%C3%A3-romualdo-4606684.jpg?alt=media\&token=ca70b21c-4d00-4317-8ba3-852b9cadc839)

The horizontal **array** uses the F.I.F.O. principal (First In First Out) which is the first person to get in line is the first person to get out of the line, F.I.F.O.

* *Removal -> The end of an array*
* *Adding -> the beginning of the array*
* *Example: a line for fast food, a line for a new Iphone, a line at Disneyland*
