Skip to content

Commit

Permalink
Merge pull request #20 from pedropark99/data-structures
Browse files Browse the repository at this point in the history
Add chapter for Data structures
  • Loading branch information
pedropark99 authored Aug 10, 2024
2 parents a1c64c0 + 224743e commit 282a024
Show file tree
Hide file tree
Showing 54 changed files with 5,429 additions and 48 deletions.
11 changes: 10 additions & 1 deletion Chapters/01-zig-weird.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@ const ls = [_]f64{432.1, 87.2, 900.05};
_ = ns; _ = ls;
```

Is worth noting that these are static arrays, meaning that
they cannot grow in size.
Once you declare your array, you cannot change the size of it.
This is very commom in low level languages.
Because low level languages normally wants to give you (the programmer) full control over memory,
and the way in which arrays are expanded is tightly related to
memory management.


### Selecting elements of the array

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


## Blocks and scopes
## Blocks and scopes {#sec-blocks}

Blocks are created in Zig by a pair of curly braces. A block is just a group of
expressions (or statements) contained inside of a pair of curly braces. All of these expressions that
Expand Down
863 changes: 859 additions & 4 deletions Chapters/09-data-structures.qmd

Large diffs are not rendered by default.

711 changes: 711 additions & 0 deletions Chapters/10-stack-project.qmd

Large diffs are not rendered by default.

Binary file added Figures/Powerpoint/doubly-linked-list.odp
Binary file not shown.
Binary file added Figures/Powerpoint/dynamic-array.odp
Binary file not shown.
Binary file added Figures/Powerpoint/linked-list.odp
Binary file not shown.
Binary file added Figures/doubly-linked-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Figures/dynamic-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions Figures/hashtable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions Figures/lifo-stack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Figures/linked-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions ZigExamples/data-structures/generic_array.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const std = @import("std");
fn Array(comptime T: type) type {
return struct {
items: []T,
size: usize,
};
}

pub fn main() !void {
var buffer: [5]u8 = undefined;
const ar = Array(u8){ .items = &buffer, .size = 0 };
std.debug.print("{any}\n", .{@TypeOf(ar)});
}
Loading

0 comments on commit 282a024

Please sign in to comment.