diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-25 15:12:12 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-25 15:12:12 +0000 |
| commit | 7d1944ab9d2307f2736afe8520436872db1c7617 (patch) | |
| tree | 7380a4f148f9ce0b70ed9f02cfa5e8561c783a7a /examples/data_structures | |
| parent | 8b720543f538862796fec0ff6b7ea12cb140bf0f (diff) | |
'let' it be
Diffstat (limited to 'examples/data_structures')
| -rw-r--r-- | examples/data_structures/binary_tree.zc | 4 | ||||
| -rw-r--r-- | examples/data_structures/linked_list.zc | 16 | ||||
| -rw-r--r-- | examples/data_structures/stack.zc | 12 |
3 files changed, 16 insertions, 16 deletions
diff --git a/examples/data_structures/binary_tree.zc b/examples/data_structures/binary_tree.zc index 14e7b3d..86acb21 100644 --- a/examples/data_structures/binary_tree.zc +++ b/examples/data_structures/binary_tree.zc @@ -8,7 +8,7 @@ struct Node { impl Node { fn new(v: int) -> Self* { - var n = alloc<Self>(); + let n = alloc<Self>(); n.value = v; n.left = NULL; n.right = NULL; @@ -71,7 +71,7 @@ impl BST { } fn main() { - var tree = BST::new(); + let tree = BST::new(); defer tree.free(); "Inserting: 50, 30, 20, 40, 70, 60, 80"; diff --git a/examples/data_structures/linked_list.zc b/examples/data_structures/linked_list.zc index cb85554..cd16bf5 100644 --- a/examples/data_structures/linked_list.zc +++ b/examples/data_structures/linked_list.zc @@ -8,7 +8,7 @@ struct Node { impl Node { fn new(v: int) -> Self* { - var n = alloc<Node>(); + let n = alloc<Node>(); guard n != NULL else { "Out of memory!"; return NULL; @@ -29,7 +29,7 @@ impl LinkedList { } fn push(self, v: int) { - var new_node = Node::new(v); + let new_node = Node::new(v); guard new_node != NULL else { return; } new_node.next = self.head; @@ -37,7 +37,7 @@ impl LinkedList { } fn print_list(self) { - var current: Node* = self.head; + let current: Node* = self.head; "["..; while current != NULL { "{current.value}"..; @@ -50,17 +50,17 @@ impl LinkedList { } fn free(self) { - var current: Node* = self.head; + let current: Node* = self.head; while current != NULL { - autofree var temp = current; + autofree let temp = current; current = current.next; } self.head = NULL; } fn len(self) -> int { - var count = 0; - var current: Node* = self.head; + let count = 0; + let current: Node* = self.head; while current != NULL { count++; current = current.next; @@ -70,7 +70,7 @@ impl LinkedList { } fn main() { - var list = LinkedList::new(); + let list = LinkedList::new(); defer list.free(); "Pushing: 10, 20, 30..."; diff --git a/examples/data_structures/stack.zc b/examples/data_structures/stack.zc index 8f1fea5..4a8593a 100644 --- a/examples/data_structures/stack.zc +++ b/examples/data_structures/stack.zc @@ -43,7 +43,7 @@ impl Stack<T> { fn main() { "[Integer Stack]"; - var int_stack = Stack<int>::new(); + let int_stack = Stack<int>::new(); defer int_stack.free(); "Pushing: 10, 20, 30"; @@ -52,19 +52,19 @@ fn main() { int_stack.push(30); "Size: {int_stack.size()}"; - var p = int_stack.peek(); + let p = int_stack.peek(); "Peek: {p.unwrap()}"; "Popping: "..; while !int_stack.is_empty() { - var opt = int_stack.pop(); + let opt = int_stack.pop(); "{opt.unwrap()} "..; } ""; ""; "[String Stack]"; - var str_stack = Stack<String>::new(); + let str_stack = Stack<String>::new(); defer str_stack.free(); str_stack.push(String::new("First")); @@ -73,8 +73,8 @@ fn main() { "Popping: "..; while !str_stack.is_empty() { - var opt_s = str_stack.pop(); - var s: String = opt_s.unwrap(); + let opt_s = str_stack.pop(); + let s: String = opt_s.unwrap(); "{s.c_str()} "..; } ""; |
