mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-28 00:24:21 +00:00
feat: Add ruby code - chapter "array & linked list" (#1158)
* feat: add ruby code chapter array & linked list - array.rb - linked_list.rb - list.rb - my_list.rb * feat: add ruby code blocks * chore: fix convention
This commit is contained in:
@@ -119,6 +119,14 @@ Arrays can be initialized in two ways depending on the needs: either without ini
|
||||
var nums = [_]i32{ 1, 3, 2, 5, 4 };
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="array.rb"
|
||||
# Initialize array
|
||||
arr = Array.new(5, 0) # [ 0, 0, 0, 0, 0 ]
|
||||
nums = [1, 3, 2, 5, 4]
|
||||
```
|
||||
|
||||
### Accessing Elements
|
||||
|
||||
Elements in an array are stored in contiguous memory spaces, making it simpler to compute each element's memory address. The formula shown in the Figure below aids in determining an element's memory address, utilizing the array's memory address (specifically, the first element's address) and the element's index. This computation streamlines direct access to the desired element.
|
||||
|
||||
Reference in New Issue
Block a user