Skip to content

Commit 282a024

Browse files
authored
Merge pull request #20 from pedropark99/data-structures
Add chapter for Data structures
2 parents a1c64c0 + 224743e commit 282a024

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5429
-48
lines changed

Chapters/01-zig-weird.qmd

+10-1
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,15 @@ const ls = [_]f64{432.1, 87.2, 900.05};
783783
_ = ns; _ = ls;
784784
```
785785

786+
Is worth noting that these are static arrays, meaning that
787+
they cannot grow in size.
788+
Once you declare your array, you cannot change the size of it.
789+
This is very commom in low level languages.
790+
Because low level languages normally wants to give you (the programmer) full control over memory,
791+
and the way in which arrays are expanded is tightly related to
792+
memory management.
793+
794+
786795
### Selecting elements of the array
787796

788797
One very commom activity is to select specific portions of an array
@@ -915,7 +924,7 @@ try stdout.print("{any}\n", .{c});
915924
```
916925

917926

918-
## Blocks and scopes
927+
## Blocks and scopes {#sec-blocks}
919928

920929
Blocks are created in Zig by a pair of curly braces. A block is just a group of
921930
expressions (or statements) contained inside of a pair of curly braces. All of these expressions that

Chapters/09-data-structures.qmd

+859-4
Large diffs are not rendered by default.

Chapters/10-stack-project.qmd

+711
Large diffs are not rendered by default.
18.8 KB
Binary file not shown.

Figures/Powerpoint/dynamic-array.odp

25.7 KB
Binary file not shown.

Figures/Powerpoint/linked-list.odp

16.6 KB
Binary file not shown.

Figures/doubly-linked-list.png

29.2 KB
Loading

Figures/dynamic-array.png

221 KB
Loading

Figures/hashtable.svg

+170
Loading

Figures/lifo-stack.svg

+165
Loading

Figures/linked-list.png

20.3 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const std = @import("std");
2+
fn Array(comptime T: type) type {
3+
return struct {
4+
items: []T,
5+
size: usize,
6+
};
7+
}
8+
9+
pub fn main() !void {
10+
var buffer: [5]u8 = undefined;
11+
const ar = Array(u8){ .items = &buffer, .size = 0 };
12+
std.debug.print("{any}\n", .{@TypeOf(ar)});
13+
}

0 commit comments

Comments
 (0)