Skip to content

Commit 3f108a8

Browse files
june128leios
authored andcommitted
Update C# files fit the new CSharp repository. Fix import. (#74)
* Replace the C# bubble sort and bogo sort with their updated versions. * Replace the C# euclidean algorithm and euclidean algorithm MdAdditional file with its updated version. Fix wrong import. * Replace the C# tree traversal and tree traversal MdAdditional file with its updated version. * Replace the stable marriage files with their updated versions. * Add Program.cs for bubble sort and bogo sort. * Add Program.cs for EuclideanAlgorithm and EuclideanAlgorithmMdAdditional. * Add Program.cs for Tree and TreeMdAdditional.
1 parent 3787658 commit 3f108a8

File tree

21 files changed

+254
-211
lines changed

21 files changed

+254
-211
lines changed

chapters/decision_problems/stable_marriage/code/cs/GaleShapleyAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
22
using System.Collections.Generic;
33

4-
namespace ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley
4+
namespace StableMarriageProblem
55
{
66
public static class GaleShapleyAlgorithm<TFollow, TLead>
77
where TFollow : Person<TFollow, TLead>

chapters/decision_problems/stable_marriage/code/cs/ListExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace ArcaneAlgorithmArchive.Extensions
4+
namespace StableMarriageProblem
55
{
66
public static class ListExtensions
77
{

chapters/decision_problems/stable_marriage/code/cs/Person.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
22
using System.Collections.Generic;
33

4-
namespace ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley
4+
namespace StableMarriageProblem
55
{
66
public class Person<TSelf, TPref>
77
where TSelf : Person<TSelf, TPref>
Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,67 @@
1-
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
2-
using System;
3-
using System.Collections.Generic;
4-
using ArcaneAlgorithmArchive.ComputationalMathematics.DecisionProblems.GaleShapley;
5-
using ArcaneAlgorithmArchive.Extensions;
6-
7-
namespace ArcaneAlgorithmArchiveCLI
8-
{
9-
class MainClass
10-
{
11-
public static void Main(string[] args)
12-
{
13-
Console.WriteLine("GaleShapley");
14-
// Using men and women as an example.
15-
var men = new List<Man>()
16-
{
17-
new Man("A"),
18-
new Man("B"),
19-
new Man("C"),
20-
new Man("D"),
21-
new Man("E")
22-
};
23-
var women = new List<Woman>()
24-
{
25-
new Woman("F"),
26-
new Woman("G"),
27-
new Woman("H"),
28-
new Woman("I"),
29-
new Woman("J"),
30-
};
31-
32-
var random = new Random();
33-
34-
foreach (var man in men)
35-
{
36-
man.Choices = new List<Woman>(women).Shuffle(random);
37-
Console.WriteLine(man.Name + ":");
38-
foreach (var choice in man.Choices)
39-
Console.Write(choice.Name);
40-
Console.WriteLine();
41-
}
42-
foreach (var woman in women)
43-
{
44-
woman.Choices = new List<Man>(men).Shuffle(random);
45-
Console.WriteLine(woman.Name + ":");
46-
foreach (var choice in woman.Choices)
47-
Console.Write(choice.Name);
48-
Console.WriteLine();
49-
}
50-
51-
GaleShapleyAlgorithm<Woman, Man>.RunGaleShapleyAlgorithm(women, men);
52-
53-
foreach (var woman in women)
54-
{
55-
Console.WriteLine(woman.Name + " : " + woman?.Partner.Name);
56-
}
57-
Console.WriteLine();
58-
}
59-
}
60-
61-
// for GaleShapley
62-
public class Man : Person<Man, Woman>
63-
{
64-
public Man(string name) : base(name) { }
65-
}
66-
67-
public class Woman : Person<Woman, Man>
68-
{
69-
public Woman(string name) : base(name) { }
70-
}
71-
}
1+
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace StableMarriageProblem
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("GaleShapleyAlgorithm");
12+
// Using men and women as an example.
13+
var men = new List<Man>()
14+
{
15+
new Man("A"),
16+
new Man("B"),
17+
new Man("C"),
18+
new Man("D"),
19+
new Man("E")
20+
};
21+
var women = new List<Woman>()
22+
{
23+
new Woman("F"),
24+
new Woman("G"),
25+
new Woman("H"),
26+
new Woman("I"),
27+
new Woman("J"),
28+
};
29+
30+
var random = new Random();
31+
32+
foreach (var man in men)
33+
{
34+
man.Choices = new List<Woman>(women).Shuffle(random);
35+
Console.WriteLine(man.Name + ":");
36+
foreach (var choice in man.Choices)
37+
Console.Write(choice.Name);
38+
Console.WriteLine();
39+
}
40+
foreach (var woman in women)
41+
{
42+
woman.Choices = new List<Man>(men).Shuffle(random);
43+
Console.WriteLine(woman.Name + ":");
44+
foreach (var choice in woman.Choices)
45+
Console.Write(choice.Name);
46+
Console.WriteLine();
47+
}
48+
49+
GaleShapleyAlgorithm<Woman, Man>.RunGaleShapleyAlgorithm(women, men);
50+
51+
foreach (var woman in women)
52+
{
53+
Console.WriteLine(woman.Name + " : " + woman?.Partner.Name);
54+
}
55+
}
56+
}
57+
58+
public class Man : Person<Man, Woman>
59+
{
60+
public Man(string name) : base(name) { }
61+
}
62+
63+
public class Woman : Person<Woman, Man>
64+
{
65+
public Woman(string name) : base(name) { }
66+
}
67+
}

chapters/euclidean_algorithm/code/cs/EuclideanAlgorithm.cs renamed to chapters/euclidean_algorithm/code/cs/EuclideanAlgorithm/EuclideanAlgorithm.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
1+
// submitted by Julian Schacher (jspp)
2+
using System;
23

3-
namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.EuclideanAlgorithm
4+
namespace EuclideanAlgorithm
45
{
56
public static class EuclideanAlgorithm
67
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// submitted by Julian Schacher (jspp)
2+
using System;
3+
4+
namespace EuclideanAlgorithm
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
Console.WriteLine("EuclideanAlgorithm");
11+
int check = EuclideanAlgorithm.EuclidMod(64 * 67, 64 * 81);
12+
int check2 = EuclideanAlgorithm.EuclidSub(128 * 12, 128 * 77);
13+
14+
Console.WriteLine(check);
15+
Console.WriteLine(check2);
16+
}
17+
}
18+
}

chapters/euclidean_algorithm/code/cs/EuclideanAlgorithmMdAdditional.cs renamed to chapters/euclidean_algorithm/code/cs/EuclideanAlgorithmMdAdditional/EuclideanAlgorithmMdAdditional.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// submitted by Julian Schacher (jspp)
2-
namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.EuclideanAlgorithm
2+
namespace EuclideanAlgorithmMdAdditional
33
{
44
public class EuclideanAlgorithmMdAdditional
55
{
@@ -28,15 +28,4 @@ public static int EuclidMod(int a, int b)
2828
return a;
2929
}
3030
}
31-
class MainClass
32-
{
33-
public static void Main(string[] args)
34-
{
35-
int check = EuclideanAlgorithm.EuclidMod(64 * 67, 64 * 81);
36-
int check2 = EuclideanAlgorithm.EuclidSub(128 * 12, 128 * 77);
37-
38-
Console.WriteLine(check);
39-
Console.WriteLine(check2);
40-
}
41-
}
4231
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// submitted by Julian Schacher (jspp)
2+
using System;
3+
4+
namespace EuclideanAlgorithmMdAdditional
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
Console.WriteLine("EuclideanAlgorithmMdAdditional");
11+
int checkMdAdditional = EuclideanAlgorithmMdAdditional.EuclidMod(64 * 67, 64 * 81);
12+
int checkMdAdditional2 = EuclideanAlgorithmMdAdditional.EuclidSub(128 * 12, 128 * 77);
13+
14+
Console.WriteLine(checkMdAdditional);
15+
Console.WriteLine(checkMdAdditional2);
16+
}
17+
}
18+
}

chapters/euclidean_algorithm/euclidean.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
3131
{% sample lang="c" %}
3232
[import:18-33, lang="c_cpp"](code/c/euclidean_example.c)
3333
{% sample lang="cs" %}
34-
[import:6-17, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
34+
[import:6-17, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional/EuclideanAlgorithmMdAdditional.cs)
3535
{% sample lang="clj" %}
3636
[import:1-7, lang="clojure"](code/clojure/euclidean_example.clj)
3737
{% sample lang="cpp" %}
@@ -62,7 +62,7 @@ Modern implementations, though, often use the modulus operator (%) like so
6262
{% sample lang="c" %}
6363
[import:4-16, lang="c_cpp"](code/c/euclidean_example.c)
6464
{% sample lang="cs" %}
65-
[import:19-29, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
65+
[import:19-29, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional/EuclideanAlgorithmMdAdditional.cs)
6666
{% sample lang="clj" %}
6767
[import:8-12, lang="clojure"](code/clojure/euclidean_example.clj)
6868
{% sample lang="cpp" %}
@@ -97,7 +97,10 @@ The Euclidean Algorithm is truly fundamental to many other algorithms throughout
9797
[import, lang="c_cpp"](code/c/euclidean_example.c)
9898
{% sample lang="cs" %}
9999
### C# #
100-
[import, lang="csharp"](code/cs/EuclideanAlgorithmMdAdditional.cs)
100+
EuclideanAlgorithm.cs
101+
[import, lang="csharp"](code/cs/EuclideanAlgorithm/EuclideanAlgorithm.cs)
102+
Program.cs
103+
[import, lang="csharp"](code/cs/EuclideanAlgorithm/Program.cs)
101104
{% sample lang="clj" %}
102105
### Clojure
103106
[import, lang="clojure"](code/clojure/euclidean_example.clj)

chapters/sorting_searching/bogo/bogo_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ In code, it looks something like this:
3939
{% sample lang="jl" %}
4040
[import:1-14, lang:"julia"](code/julia/bogo.jl)
4141
{% sample lang="cs" %}
42-
[import:29-35, lang:"csharp"](code/cs/bogo.cs)
42+
[import:9-15, lang:"csharp"](code/cs/BogoSort.cs)
4343
{% sample lang="clj" %}
4444
[import:6-10, lang:"clojure"](code/clojure/bogo.clj)
4545
{% endmethod %}

chapters/sorting_searching/bogo/code/cs/bogo.cs renamed to chapters/sorting_searching/bogo/code/cs/BogoSort.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,11 @@
22
using System;
33
using System.Collections.Generic;
44

5-
namespace ArcaneAlgorithmArchive.FundamentalAlgorithms.SortingSearching
5+
namespace BogoSort
66
{
7-
public static class Sorting
7+
public static class BogoSort
88
{
9-
public static List<T> BubbleSort<T>(List<T> list) where T : IComparable<T>
10-
{
11-
var length = list.Count;
12-
13-
for (int i = 0; i < length; i++)
14-
{
15-
for (int j = 1; j < length; j++)
16-
{
17-
if (list[j - 1].CompareTo(list[j]) > 0)
18-
{
19-
var temp = list[j - 1];
20-
list[j - 1] = list[j];
21-
list[j] = temp;
22-
}
23-
}
24-
}
25-
26-
return list;
27-
}
28-
29-
public static List<T> BogoSort<T>(List<T> list) where T : IComparable<T>
9+
public static List<T> RunBogoSort<T>(List<T> list) where T : IComparable<T>
3010
{
3111
while (!IsSorted(list))
3212
list = Shuffle(list, new Random());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// submitted by Julian Schacher (jspp)
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace BogoSort
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("BogoSort");
12+
var listBogo = new List<int>() { 1, 2, 6, 4, 9, 54, 3, 2, 7, 15 };
13+
Console.Write("unsorted: ");
14+
foreach (var number in listBogo)
15+
Console.Write(number + " ");
16+
Console.WriteLine();
17+
listBogo = BogoSort.RunBogoSort(listBogo);
18+
Console.Write("sorted: ");
19+
foreach (var number in listBogo)
20+
Console.Write(number + " ");
21+
Console.WriteLine();
22+
}
23+
}
24+
}

chapters/sorting_searching/bubble/bubble_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
3434
{% sample lang="jl" %}
3535
[import:1-10, lang:"julia"](code/julia/bubble.jl)
3636
{% sample lang="cs" %}
37-
[import:9-27, lang:"csharp"](code/cs/Sorting.cs)
37+
[import:9-27, lang:"csharp"](code/cs/BubbleSort.cs)
3838
{% endmethod %}
3939

4040
... And that's it for the simplest bubble sort method.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// submitted by Julian Schacher (jspp)
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace BubbleSort
6+
{
7+
public static class BubbleSort
8+
{
9+
public static List<T> RunBubbleSort<T>(List<T> list) where T : IComparable<T>
10+
{
11+
var length = list.Count;
12+
13+
for (int i = 0; i < length; i++)
14+
{
15+
for (int j = 1; j < length; j++)
16+
{
17+
if (list[j - 1].CompareTo(list[j]) > 0)
18+
{
19+
var temp = list[j - 1];
20+
list[j - 1] = list[j];
21+
list[j] = temp;
22+
}
23+
}
24+
}
25+
26+
return list;
27+
}
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// submitted by Julian Schacher (jspp)
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace BubbleSort
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("BubbleSort");
12+
var listBubble = new List<int>() { 1, 2, 6, 4, 9, 54, 3, 2, 7, 15 };
13+
Console.Write("unsorted: ");
14+
foreach (var number in listBubble)
15+
Console.Write(number + " ");
16+
Console.WriteLine();
17+
listBubble = BubbleSort.RunBubbleSort(listBubble);
18+
Console.Write("sorted: ");
19+
foreach (var number in listBubble)
20+
Console.Write(number + " ");
21+
Console.WriteLine();
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)