diff --git a/docs/programming-fundamentals/language-syntax/arrays.md b/docs/programming-fundamentals/language-syntax/arrays.md new file mode 100644 index 000000000..32afd27d3 --- /dev/null +++ b/docs/programming-fundamentals/language-syntax/arrays.md @@ -0,0 +1,185 @@ +--- +id: arrays +sidebar_position: 6 +title: Arrays +sidebar_label: Arrays +description: "Learn about arrays in JavaScript, Java, Python, and C++. Understand how to declare, initialize, and manipulate arrays across different programming languages." +tags: [arrays, data structures, programming, syntax, js, java, python, cpp] +--- + +Arrays are one of the most fundamental data structures in programming. They are used to store multiple values in a single variable, allowing for efficient data manipulation and access. This guide will cover how to declare, initialize, and work with arrays in JavaScript, Java, Python, and C++. + + + +## What is an Array? + +An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together to make it easier to manage them. Arrays can be indexed, modified, and iterated over to perform various operations. + +## Arrays in Different Languages + + + + +### JavaScript Arrays Overview + +In JavaScript, arrays are dynamic, which means they can change size and hold mixed data types. + +#### Declaration and Initialization + +```js title="JavaScript Array Example" +// Declaration +let fruits = ["Apple", "Banana", "Cherry"]; + +// Accessing elements +console.log(fruits[0]); // Output: Apple + +// Modifying an array +fruits[1] = "Mango"; +console.log(fruits); // Output: ["Apple", "Mango", "Cherry"] +``` + +#### Common Array Methods + +- **`push()`**: Adds an element to the end. +- **`pop()`**: Removes the last element. +- **`shift()`**: Removes the first element. +- **`unshift()`**: Adds an element to the beginning. + +```js title="JavaScript Array Methods Example" +fruits.push("Orange"); +console.log(fruits); // Output: ["Apple", "Mango", "Cherry", "Orange"] + +fruits.pop(); +console.log(fruits); // Output: ["Apple", "Mango", "Cherry"] +``` + + + + + +### Java Arrays Overview + +Java arrays have a fixed size and must be declared with a type. + +#### Declaration and Initialization + +```java title="Java Array Example" +// Declaration +int[] numbers = new int[5]; // Array of size 5 + +// Initialization +int[] primes = {2, 3, 5, 7, 11}; + +// Accessing elements +System.out.println(primes[2]); // Output: 5 + +// Modifying an array +primes[2] = 13; +System.out.println(primes[2]); // Output: 13 +``` + +#### Looping Through Arrays + +```java title="Java Looping Through Array Example" +for (int num : primes) { + System.out.println(num); +} +``` + + + + + +### Python Arrays (Lists) Overview + +In Python, lists are dynamic and can hold different data types. + +#### Declaration and Initialization + +```python title="Python List Example" +# Declaration +fruits = ["Apple", "Banana", "Cherry"] + +# Accessing elements +print(fruits[0]) # Output: Apple + +# Modifying an array +fruits[1] = "Mango" +print(fruits) # Output: ["Apple", "Mango", "Cherry"] +``` + +#### Common List Methods + +- **`append()`**: Adds an element to the end. +- **`remove()`**: Removes a specific element. +- **`pop()`**: Removes the last element. + +```python title="Python List Methods Example" +fruits.append("Orange") +print(fruits) # Output: ["Apple", "Mango", "Cherry", "Orange"] + +fruits.pop() +print(fruits) # Output: ["Apple", "Mango", "Cherry"] +``` + + + + + +### C++ Arrays Overview + +C++ arrays are static and have a fixed size. + +#### Declaration and Initialization + +```cpp title="C++ Array Example" +// Declaration +int numbers[5]; // Array of size 5 + +// Initialization +int primes[] = {2, 3, 5, 7, 11}; + +// Accessing elements +std::cout << primes[2] << std::endl; // Output: 5 + +// Modifying an array +primes[2] = 13; +std::cout << primes[2] << std::endl; // Output: 13 +``` + +#### Looping Through Arrays + +```cpp title="C++ Looping Through Array Example" +for (int i = 0; i < 5; i++) { + std::cout << primes[i] << " "; +} +``` + + + + + + +## Visualizing Arrays with Mermaid + +Below is a simple Mermaid diagram to visualize how an array is structured in memory. + +```mermaid +graph LR; + A[0] -->|Index 0| B[Apple]; + B -->|Index 1| C[Banana]; + C -->|Index 2| D[Cherry]; + D -->|Index 3| E[Orange]; +``` + +
+ +This representation shows how each element in an array can be accessed by its index. + + + +--- + +

Feedback and Support

+ + \ No newline at end of file diff --git a/src/css/custom.css b/src/css/custom.css index f600c6add..99c34f553 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -136,6 +136,28 @@ html[data-theme='dark'] .noise-bg { background-image: url('/landing/grid-dark.svg'); } +.theme-doc-markdown header { + background-image: linear-gradient( + to bottom, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 0.6) + ), + url('/banner/banner-13.jpg'); + background-position: center; + padding: 2rem 1rem; + margin-bottom: 2rem; + border-bottom: 1px solid var(--ifm-color-primary-lightest); + background-size: cover; + background-repeat: no-repeat; + border-radius: 0.5rem; +} + +html[data-theme='dark'] .theme-doc-markdown header { + /* background-image: url('/banner/banner-1.png'); */ + background-image: url('/banner/banner-10.jpg'); +} + + .footer { background-color: #001; } diff --git a/static/banner/banner-1.jpg b/static/banner/banner-1.jpg new file mode 100644 index 000000000..bb91df0c6 Binary files /dev/null and b/static/banner/banner-1.jpg differ diff --git a/static/banner/banner-1.png b/static/banner/banner-1.png new file mode 100644 index 000000000..0ff261565 Binary files /dev/null and b/static/banner/banner-1.png differ diff --git a/static/banner/banner-10.jpg b/static/banner/banner-10.jpg new file mode 100644 index 000000000..331e4ffe9 Binary files /dev/null and b/static/banner/banner-10.jpg differ diff --git a/static/banner/banner-11.jpg b/static/banner/banner-11.jpg new file mode 100644 index 000000000..dc7b45e90 Binary files /dev/null and b/static/banner/banner-11.jpg differ diff --git a/static/banner/banner-13.jpg b/static/banner/banner-13.jpg new file mode 100644 index 000000000..64fc2672a Binary files /dev/null and b/static/banner/banner-13.jpg differ diff --git a/static/banner/banner-2.avif b/static/banner/banner-2.avif new file mode 100644 index 000000000..69974d674 Binary files /dev/null and b/static/banner/banner-2.avif differ diff --git a/static/banner/banner-2.jpg b/static/banner/banner-2.jpg new file mode 100644 index 000000000..8a9db4ea6 Binary files /dev/null and b/static/banner/banner-2.jpg differ diff --git a/static/banner/banner-3.jpg b/static/banner/banner-3.jpg new file mode 100644 index 000000000..d22825886 Binary files /dev/null and b/static/banner/banner-3.jpg differ diff --git a/static/banner/banner-4.jpg b/static/banner/banner-4.jpg new file mode 100644 index 000000000..c612de020 Binary files /dev/null and b/static/banner/banner-4.jpg differ diff --git a/static/banner/banner-5.jpg b/static/banner/banner-5.jpg new file mode 100644 index 000000000..dd28a0a27 Binary files /dev/null and b/static/banner/banner-5.jpg differ diff --git a/static/banner/banner-8.jpg b/static/banner/banner-8.jpg new file mode 100644 index 000000000..e1e808d57 Binary files /dev/null and b/static/banner/banner-8.jpg differ diff --git a/static/banner/banner-9.jpg b/static/banner/banner-9.jpg new file mode 100644 index 000000000..8823bc65b Binary files /dev/null and b/static/banner/banner-9.jpg differ diff --git a/static/img/logo.png b/static/img/logo.png deleted file mode 100644 index 09adb638f..000000000 Binary files a/static/img/logo.png and /dev/null differ