14 lines
362 B
Text
14 lines
362 B
Text
require "list"
|
|
local fmt = require "fmt"
|
|
|
|
-- Create a singly-linked list containing the first 50 positive integers.
|
|
local s = slist.of(range(1, 50):unpack())
|
|
|
|
-- Now traverse and print them in tabular form.
|
|
local node = s:node(1)
|
|
local count = 0
|
|
while node do
|
|
fmt.write("%4d ", node.value)
|
|
node = node.next
|
|
if ++count % 10 == 0 then print() end
|
|
end
|