All examplesLanguage Install Aner
A basic integer linked list
Build Node and LinkedList classes, append or prepend integers, and traverse nullable links after checking for null.
// Basic singly linked list of Int64 values.
class Node {
public let value: Int64
public var next: Node?
}
class LinkedList {
var head: Node?
fn prepend(value: Int64) {
head = Node(value: value, next: head)
}
fn append(value: Int64) {
let node = Node(value: value, next: null)
if head == null {
head = node
return
}
var cursor = head
while cursor.next != null {
cursor = cursor.next
}
cursor.next = node
}
fn len() {
var count = 0
var cursor = head
while cursor != null {
count = count + 1
cursor = cursor.next
}
return count
}
}
let numbers = LinkedList(head: null)
numbers.append(20)
numbers.prepend(10)
numbers.append(30)
print(numbers.len()) // 3
Make it your experiment.
Use Aner 0.0.3 or newer. Save this program as examples/linkedlist_basic.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/linkedlist_basic.aner
aner run examples/linkedlist_basic.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution