From 22c72c3c8d010c0c493878973cac927a18472c3c Mon Sep 17 00:00:00 2001 From: didier amyot Date: Mon, 21 Aug 2023 10:06:31 -0400 Subject: [PATCH] added new exo --- Algorithms/IntChainLink.cs | 29 +++++++++++++++++++++++++++++ Algorithms/Program.cs | 15 +++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 Algorithms/IntChainLink.cs diff --git a/Algorithms/IntChainLink.cs b/Algorithms/IntChainLink.cs new file mode 100644 index 0000000..a69814d --- /dev/null +++ b/Algorithms/IntChainLink.cs @@ -0,0 +1,29 @@ +namespace Algorithms; + +public class IntChainLink +{ + private int value; + private IntChainLink? lst; + + public IntChainLink(int value) + { + this.value = value; + this.lst = null; + } + + public IntChainLink(int value, IntChainLink lst) + { + this.value = value; + this.lst = lst; + } + + public int Head() + { + return value; + } + + public IntChainLink Rest() + { + return lst!; + } +} \ No newline at end of file diff --git a/Algorithms/Program.cs b/Algorithms/Program.cs index 4aa0c80..3f62ea9 100644 --- a/Algorithms/Program.cs +++ b/Algorithms/Program.cs @@ -4,12 +4,19 @@ using System; -class EntryPoint{ +class EntryPoint +{ - public static void Main(String[] args){ - + public static void Main(String[] args) + { - Console.WriteLine(TriangleExercice.BuildTriangle(6) ); + + IntChainLink lastLink = new IntChainLink(3); + IntChainLink secondLink = new IntChainLink(2, lastLink); + IntChainLink firstLink = new IntChainLink(1, secondLink); + Console.WriteLine(firstLink.Head()); // 1 + Console.WriteLine(firstLink.Rest().Head()); // 2 + Console.WriteLine(firstLink.Rest().Rest().Head()); // 3 } }