From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tigrou/linked-list/linked-list.tig | 24 ++++++++++++++++++++++++ tigrou/linked-list/linked-list.tih | 15 +++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tigrou/linked-list/linked-list.tig create mode 100644 tigrou/linked-list/linked-list.tih (limited to 'tigrou/linked-list') diff --git a/tigrou/linked-list/linked-list.tig b/tigrou/linked-list/linked-list.tig new file mode 100644 index 0000000..04c8a29 --- /dev/null +++ b/tigrou/linked-list/linked-list.tig @@ -0,0 +1,24 @@ +let + import "linked-list.tih" + var list := node { value = 0, next = nil } + + function test_lists(expected: string) = + ( + print(concat("Expected : { ", expected)); + print(" }\ngot : { "); + display(list); + print(" }\n\n") + ) +in + test_lists("0"); + + print("Adding '1' ...\n"); + append(list, 1); + + test_lists("0 -> 1"); + + print("Adding '2' ...\n"); + append(list, 2); + + test_lists("0 -> 1 -> 2") +end diff --git a/tigrou/linked-list/linked-list.tih b/tigrou/linked-list/linked-list.tih new file mode 100644 index 0000000..b890f3a --- /dev/null +++ b/tigrou/linked-list/linked-list.tih @@ -0,0 +1,15 @@ +type node = {value : int, next : node} +function append(list: node, element: int) = + if list.next = nil then + list.next := node{value = element, next = nil} + else + append(list.next, element) + +function display(list: node) = + if list <> nil then + ( + print_int(list.value); + (if list.next <> nil then + print(" -> ")); + display(list.next) + ) -- cgit v1.2.3