Skip to content

Commit

Permalink
Add W3 D2 programs
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Sep 19, 2023
1 parent f8a67f2 commit 6eb5e7a
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 1 deletion.
40 changes: 39 additions & 1 deletion FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down Expand Up @@ -107,6 +107,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MyPractice", "MyPractice",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Youtube", "MyPractice\Youtube\Youtube.csproj", "{1EC38B64-67FE-4276-B62E-2714BC280EE5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W3 D2", "W3 D2", "{24A9828C-37FB-41FF-AD85-C74FD61DFF50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Array", "W3 D2\Array\Array.csproj", "{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArrayList", "W3 D2\ArrayList\ArrayList.csproj", "{E8E9CC1D-539D-4849-8B29-09FFC9308392}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashSet", "W3 D2\HashSet\HashSet.csproj", "{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinkedList", "W3 D2\LinkedList\LinkedList.csproj", "{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "List", "W3 D2\List\List.csproj", "{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -281,11 +293,32 @@ Global
{1EC38B64-67FE-4276-B62E-2714BC280EE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EC38B64-67FE-4276-B62E-2714BC280EE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EC38B64-67FE-4276-B62E-2714BC280EE5}.Release|Any CPU.Build.0 = Release|Any CPU
{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC}.Release|Any CPU.Build.0 = Release|Any CPU
{E8E9CC1D-539D-4849-8B29-09FFC9308392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8E9CC1D-539D-4849-8B29-09FFC9308392}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8E9CC1D-539D-4849-8B29-09FFC9308392}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8E9CC1D-539D-4849-8B29-09FFC9308392}.Release|Any CPU.Build.0 = Release|Any CPU
{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC39434B-0FCF-4A5F-A86C-8892670D1AC8}.Release|Any CPU.Build.0 = Release|Any CPU
{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3}.Release|Any CPU.Build.0 = Release|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A718291C-B218-4283-837F-43CF360568AC} = {A718291C-B218-4283-837F-43CF360568AC}
{77D0C1C7-A06B-4E05-9458-873709BD4BFD} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{AA5CB577-831E-40F5-AABD-AFF7C56F8A57} = {44C682DF-E1C9-4394-813D-0CB989CD9262}
{1A0A5FD8-8FC2-4ECA-8EB0-BAC6DF70E7BF} = {0458C07F-2B31-4DB7-97E4-315800A0B2C0}
Expand Down Expand Up @@ -328,5 +361,10 @@ Global
{3B5564AD-79B1-457F-B755-9FA9DEDB3A4D} = {FDC6C9B3-986B-4EB0-84D7-96609709D9FC}
{B0E44C63-88D6-4812-B0C7-DC0185BA98F5} = {FDC6C9B3-986B-4EB0-84D7-96609709D9FC}
{1EC38B64-67FE-4276-B62E-2714BC280EE5} = {B7BF6991-6661-4DAF-BC8F-7E0A82F7E090}
{C812F926-1AC2-4C07-B3C7-16E2BA57E5CC} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50}
{E8E9CC1D-539D-4849-8B29-09FFC9308392} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50}
{AC39434B-0FCF-4A5F-A86C-8892670D1AC8} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50}
{2E8B2B36-98E9-4ACC-BE46-0332F53A1AE3} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50}
{5F05DFBC-6EF9-4F4F-8B6D-4E1490171568} = {24A9828C-37FB-41FF-AD85-C74FD61DFF50}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions W3 D2/Array/Array.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions W3 D2/Array/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Program
{
static void Main()
{
// two ways to create Array
int[] numbers1 = {1, 2, 3, 4, 5};
int[] numbers2 = new int[5];
numbers2[0] = 1;
numbers2[1] = 2;
numbers2[2] = 3;
numbers2[3] = 4;
numbers2[4] = 5;

// resize array
Array.Resize(ref numbers1, 10);
Console.WriteLine(numbers1.Length);

// reverse array
Array.Reverse(numbers2); // 5 4 3 2 1
foreach (var number in numbers2)
{
Console.WriteLine(number);
}

// sort array -> ascending
Array.Sort(numbers2);
foreach (var number in numbers2)
{
Console.WriteLine(number);
}
}
}
10 changes: 10 additions & 0 deletions W3 D2/ArrayList/ArrayList.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions W3 D2/ArrayList/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections;

public class Program
{
static void Main()
{
// ArrayList is not safety
ArrayList list = new ArrayList() {
1, "2", true, 3.4, 123.1f, 111M, new int[] {1, 2, 3}
};

// must unbox to access element of ArrayList
int intValue = (int) list[0];
Console.WriteLine(intValue);
}
}
10 changes: 10 additions & 0 deletions W3 D2/HashSet/HashSet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
43 changes: 43 additions & 0 deletions W3 D2/HashSet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public class Program
{
static void Main()
{
// HashSet is type safety
// HashSet elements must be unique
HashSet<int> hs1 = new();
hs1.Add(1);
hs1.Add(2);
hs1.Add(2); // this will be discarded
hs1.Add(3);
hs1.Add(4);
PrintHashSet(hs1, nameof(hs1));

HashSet<int> hs2 = new HashSet<int>() {3, 4, 5, 6};
PrintHashSet(hs2, nameof(hs2));

HashSet<int> except = new HashSet<int>(hs1);
except.ExceptWith(hs2);
PrintHashSet(except, nameof(except));

HashSet<int> union = new HashSet<int>(hs1);
union.UnionWith(hs2);
PrintHashSet(union, nameof(union));

HashSet<int> intersect = new HashSet<int>(hs1);
intersect.IntersectWith(hs2);
PrintHashSet(intersect, nameof(intersect));

Console.WriteLine($"except is subset of union: {except.IsSubsetOf(union)}");
Console.WriteLine($"union is superset of except: {union.IsSupersetOf(except)}");
}

static void PrintHashSet(HashSet<int> hashSet, string varName)
{
Console.Write(varName + ": ");
foreach (var hs in hashSet)
{
Console.Write($"{hs} ");
}
Console.WriteLine();
}
}
10 changes: 10 additions & 0 deletions W3 D2/LinkedList/LinkedList.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions W3 D2/LinkedList/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Program
{
static void Main()
{
LinkedList<int> list = new();
list.AddLast(2);
list.AddLast(3);
list.AddLast(4);
list.AddFirst(1);
list.AddLast(6);
LinkedListNode<int>? node = list.Find(6);
list.AddBefore(node, 5);
PrintLinkedList(list, nameof(list));
}

static void PrintLinkedList(LinkedList<int> list, string varName)
{
Console.Write(varName + ": ");
foreach (var item in list)
{
Console.Write($"{item} ");
}
Console.WriteLine();
}
}
25 changes: 25 additions & 0 deletions W3 D2/List/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace List;

public class Car
{
private string _brandName;
private int _topSpeed;

public string BrandName
{
get => _brandName;
set => _brandName = value;
}

public int TopSpeed
{
get => _topSpeed;
set => _topSpeed = value;
}

public Car(string brandName, int topSpeed)
{
_brandName = brandName;
_topSpeed = topSpeed;
}
}
8 changes: 8 additions & 0 deletions W3 D2/List/List.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
44 changes: 44 additions & 0 deletions W3 D2/List/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using List;

public class Program
{
static void Main()
{
List<int> listOfNumbers = new List<int>() {2, 4, 1, 9, 3, 5};
PrintList(listOfNumbers, nameof(listOfNumbers));

// Ascending
listOfNumbers.Sort();
PrintList(listOfNumbers, nameof(listOfNumbers));

listOfNumbers.Reverse();
PrintList(listOfNumbers, nameof(listOfNumbers));

List<Car> cars = new List<Car>() {new Car("honda", 200), new Car("ferrari", 400), new Car("toyota", 150)};

Console.WriteLine();
Console.WriteLine("Before sort");
foreach (var car in cars)
{
Console.WriteLine($"{car.BrandName} - {car.TopSpeed} kmh");
}

Console.WriteLine();
Console.WriteLine("After sort");
cars.Sort((car1, car2) => car1.TopSpeed.CompareTo(car2.TopSpeed)); // Sort cars based on TopSpeed
foreach (var car in cars)
{
Console.WriteLine($"{car.BrandName} - {car.TopSpeed} kmh");
}
}

static void PrintList(List<int> list, string varName)
{
Console.Write(varName + ": ");
foreach (var item in list)
{
Console.Write($"{item} ");
}
Console.WriteLine();
}
}

0 comments on commit 6eb5e7a

Please sign in to comment.