add csharp examples (#10)
This commit is contained in:
committed by
Aditya Bhargava
parent
c3396b8b0a
commit
62ed616954
2
01_introduction_to_algorithms/csharp/01_binary_search/.gitignore
vendored
Normal file
2
01_introduction_to_algorithms/csharp/01_binary_search/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/launch.json
vendored
Normal file
23
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_binary_search.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/tasks.json
vendored
Normal file
16
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var myList = new List<int> { 1, 3, 5, 7, 9 };
|
||||
Console.WriteLine(BinarySearch(myList, 3)); // => 1
|
||||
Console.WriteLine(BinarySearch(myList, -1)); // => null gets printed as an empty string
|
||||
}
|
||||
|
||||
private static int? BinarySearch(IList<int> list, int item)
|
||||
{
|
||||
var low = 0;
|
||||
var high = list.Count() - 1;
|
||||
|
||||
while (low <= high)
|
||||
{
|
||||
var mid = (low + high) / 2;
|
||||
var guess = list[mid];
|
||||
if (guess == item) return mid;
|
||||
if (guess > item)
|
||||
{
|
||||
high = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
2
02_selection_sort/csharp/01_selection_sort/.gitignore
vendored
Normal file
2
02_selection_sort/csharp/01_selection_sort/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
02_selection_sort/csharp/01_selection_sort/.vscode/launch.json
vendored
Normal file
23
02_selection_sort/csharp/01_selection_sort/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/csharp.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
02_selection_sort/csharp/01_selection_sort/.vscode/tasks.json
vendored
Normal file
16
02_selection_sort/csharp/01_selection_sort/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
41
02_selection_sort/csharp/01_selection_sort/Program.cs
Normal file
41
02_selection_sort/csharp/01_selection_sort/Program.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var arr = new List<int> { 5, 3, 6, 2, 10 };
|
||||
Console.WriteLine(string.Join(", ", SelectionSort(arr)));
|
||||
}
|
||||
|
||||
private static int[] SelectionSort(List<int> arr)
|
||||
{
|
||||
var newArr = new int[arr.Count];
|
||||
for (int i = 0; i < newArr.Length; i++)
|
||||
{
|
||||
var smallest = FindSmallest(arr);
|
||||
newArr[i] = arr[smallest];
|
||||
arr.RemoveAt(smallest);
|
||||
}
|
||||
return newArr;
|
||||
}
|
||||
|
||||
private static int FindSmallest(List<int> arr)
|
||||
{
|
||||
var smallest = arr[0];
|
||||
var smallestIndex = 0;
|
||||
for (int i = 0; i < arr.Count; i++)
|
||||
{
|
||||
if (arr[i] < smallest)
|
||||
{
|
||||
smallest = arr[i];
|
||||
smallestIndex = i;
|
||||
}
|
||||
}
|
||||
return smallestIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
02_selection_sort/csharp/01_selection_sort/project.json
Normal file
19
02_selection_sort/csharp/01_selection_sort/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
02_selection_sort/csharp/01_selection_sort/project.lock.json
Normal file
6598
02_selection_sort/csharp/01_selection_sort/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
03_recursion/csharp/01_countdown/.gitignore
vendored
Normal file
2
03_recursion/csharp/01_countdown/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
03_recursion/csharp/01_countdown/.vscode/launch.json
vendored
Normal file
23
03_recursion/csharp/01_countdown/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_countdown.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
03_recursion/csharp/01_countdown/.vscode/tasks.json
vendored
Normal file
16
03_recursion/csharp/01_countdown/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
23
03_recursion/csharp/01_countdown/Program.cs
Normal file
23
03_recursion/csharp/01_countdown/Program.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Countdown(5);
|
||||
}
|
||||
|
||||
private static void Countdown(int i)
|
||||
{
|
||||
Console.WriteLine(i);
|
||||
|
||||
// base case
|
||||
if (i <= 0) return;
|
||||
|
||||
// recursive case
|
||||
Countdown(i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
03_recursion/csharp/01_countdown/project.json
Normal file
19
03_recursion/csharp/01_countdown/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
03_recursion/csharp/01_countdown/project.lock.json
Normal file
6598
03_recursion/csharp/01_countdown/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
03_recursion/csharp/02_greet/.gitignore
vendored
Normal file
2
03_recursion/csharp/02_greet/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
03_recursion/csharp/02_greet/.vscode/launch.json
vendored
Normal file
23
03_recursion/csharp/02_greet/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_greet.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
03_recursion/csharp/02_greet/.vscode/tasks.json
vendored
Normal file
16
03_recursion/csharp/02_greet/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
30
03_recursion/csharp/02_greet/Program.cs
Normal file
30
03_recursion/csharp/02_greet/Program.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Greet("adit");
|
||||
}
|
||||
|
||||
private static void Greet(string name)
|
||||
{
|
||||
Console.WriteLine($"hello, {name}!");
|
||||
Greet2(name);
|
||||
Console.WriteLine("getting ready to say bye...");
|
||||
Bye();
|
||||
}
|
||||
|
||||
private static void Greet2(string name)
|
||||
{
|
||||
Console.WriteLine($"how are you, {name}?");
|
||||
}
|
||||
|
||||
private static void Bye()
|
||||
{
|
||||
Console.WriteLine("ok bye!");
|
||||
}
|
||||
}
|
||||
}
|
||||
19
03_recursion/csharp/02_greet/project.json
Normal file
19
03_recursion/csharp/02_greet/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
03_recursion/csharp/02_greet/project.lock.json
Normal file
6598
03_recursion/csharp/02_greet/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
03_recursion/csharp/03_factorial/.gitignore
vendored
Normal file
2
03_recursion/csharp/03_factorial/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
03_recursion/csharp/03_factorial/.vscode/launch.json
vendored
Normal file
23
03_recursion/csharp/03_factorial/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/03_factorial.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
03_recursion/csharp/03_factorial/.vscode/tasks.json
vendored
Normal file
16
03_recursion/csharp/03_factorial/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
19
03_recursion/csharp/03_factorial/Program.cs
Normal file
19
03_recursion/csharp/03_factorial/Program.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(Fact(5));
|
||||
}
|
||||
|
||||
private static int Fact(int x)
|
||||
{
|
||||
if (x <= 1) return 1;
|
||||
|
||||
return x * Fact(x - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
03_recursion/csharp/03_factorial/project.json
Normal file
19
03_recursion/csharp/03_factorial/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
03_recursion/csharp/03_factorial/project.lock.json
Normal file
6598
03_recursion/csharp/03_factorial/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
04_quicksort/csharp/01_loop_sum/.gitignore
vendored
Normal file
2
04_quicksort/csharp/01_loop_sum/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
04_quicksort/csharp/01_loop_sum/.vscode/launch.json
vendored
Normal file
23
04_quicksort/csharp/01_loop_sum/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_loop_sum.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
04_quicksort/csharp/01_loop_sum/.vscode/tasks.json
vendored
Normal file
16
04_quicksort/csharp/01_loop_sum/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
23
04_quicksort/csharp/01_loop_sum/Program.cs
Normal file
23
04_quicksort/csharp/01_loop_sum/Program.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(Sum(new[] { 1, 2, 3, 4 }));
|
||||
}
|
||||
|
||||
private static int Sum(IEnumerable<int> arr)
|
||||
{
|
||||
var total = 0;
|
||||
foreach (var x in arr)
|
||||
{
|
||||
total += x;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
04_quicksort/csharp/01_loop_sum/project.json
Normal file
19
04_quicksort/csharp/01_loop_sum/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
04_quicksort/csharp/01_loop_sum/project.lock.json
Normal file
6598
04_quicksort/csharp/01_loop_sum/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
04_quicksort/csharp/02_recursive_sum/.gitignore
vendored
Normal file
2
04_quicksort/csharp/02_recursive_sum/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
04_quicksort/csharp/02_recursive_sum/.vscode/launch.json
vendored
Normal file
23
04_quicksort/csharp/02_recursive_sum/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_recursive_sum.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
04_quicksort/csharp/02_recursive_sum/.vscode/tasks.json
vendored
Normal file
16
04_quicksort/csharp/02_recursive_sum/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
21
04_quicksort/csharp/02_recursive_sum/Program.cs
Normal file
21
04_quicksort/csharp/02_recursive_sum/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(Sum(new[] { 1, 2, 3, 4 }));
|
||||
}
|
||||
|
||||
private static int Sum(IEnumerable<int> list)
|
||||
{
|
||||
if (!list.Any()) return 0;
|
||||
|
||||
return list.Take(1).First() + Sum(list.Skip(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
04_quicksort/csharp/02_recursive_sum/project.json
Normal file
19
04_quicksort/csharp/02_recursive_sum/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
04_quicksort/csharp/02_recursive_sum/project.lock.json
Normal file
6598
04_quicksort/csharp/02_recursive_sum/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
04_quicksort/csharp/03_recursive_count/.gitignore
vendored
Normal file
2
04_quicksort/csharp/03_recursive_count/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
04_quicksort/csharp/03_recursive_count/.vscode/launch.json
vendored
Normal file
23
04_quicksort/csharp/03_recursive_count/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/03_recursive_count.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
04_quicksort/csharp/03_recursive_count/.vscode/tasks.json
vendored
Normal file
16
04_quicksort/csharp/03_recursive_count/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
21
04_quicksort/csharp/03_recursive_count/Program.cs
Normal file
21
04_quicksort/csharp/03_recursive_count/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(Count(new[] { 1, 2, 3, 4 }));
|
||||
}
|
||||
|
||||
private static int Count(IEnumerable<int> list)
|
||||
{
|
||||
if(!list.Any()) return 0;
|
||||
|
||||
return 1 + Count(list.Skip(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
04_quicksort/csharp/03_recursive_count/project.json
Normal file
19
04_quicksort/csharp/03_recursive_count/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
04_quicksort/csharp/03_recursive_count/project.lock.json
Normal file
6598
04_quicksort/csharp/03_recursive_count/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
04_quicksort/csharp/04_recursive_max/.gitignore
vendored
Normal file
2
04_quicksort/csharp/04_recursive_max/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
04_quicksort/csharp/04_recursive_max/.vscode/launch.json
vendored
Normal file
23
04_quicksort/csharp/04_recursive_max/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/04_recursive_max.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
04_quicksort/csharp/04_recursive_max/.vscode/tasks.json
vendored
Normal file
16
04_quicksort/csharp/04_recursive_max/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
23
04_quicksort/csharp/04_recursive_max/Program.cs
Normal file
23
04_quicksort/csharp/04_recursive_max/Program.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(Max(new[] { 1, 3, 2, 5, 9, 8 }));
|
||||
}
|
||||
|
||||
private static int Max(IEnumerable<int> list)
|
||||
{
|
||||
if (!list.Any()) throw new ArgumentException(nameof(list));
|
||||
if (list.Count() == 1) return list.First();
|
||||
if (list.Count() == 2) return list.First() > list.Skip(1).Take(1).First() ? list.First() : list.Skip(1).Take(1).First();
|
||||
var sub_max = Max(list.Skip(1));
|
||||
return list.First() > sub_max ? list.First() : sub_max;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
04_quicksort/csharp/04_recursive_max/project.json
Normal file
19
04_quicksort/csharp/04_recursive_max/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
04_quicksort/csharp/04_recursive_max/project.lock.json
Normal file
6598
04_quicksort/csharp/04_recursive_max/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
04_quicksort/csharp/05_quicksort/.gitignore
vendored
Normal file
2
04_quicksort/csharp/05_quicksort/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
04_quicksort/csharp/05_quicksort/.vscode/launch.json
vendored
Normal file
23
04_quicksort/csharp/05_quicksort/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/05_quicksort.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
04_quicksort/csharp/05_quicksort/.vscode/tasks.json
vendored
Normal file
16
04_quicksort/csharp/05_quicksort/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
24
04_quicksort/csharp/05_quicksort/Program.cs
Normal file
24
04_quicksort/csharp/05_quicksort/Program.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var arr = new[] { 10, 5, 2, 3 };
|
||||
Console.WriteLine(string.Join(", ", QuickSort(arr)));
|
||||
}
|
||||
|
||||
private static IEnumerable<int> QuickSort(IEnumerable<int> list)
|
||||
{
|
||||
if (list.Count() <= 1) return list;
|
||||
var pivot = list.First();
|
||||
var less = list.Skip(1).Where(i => i <= pivot);
|
||||
var greater = list.Skip(1).Where(i => i > pivot);
|
||||
return QuickSort(less).Union(new List<int> { pivot }).Union(QuickSort(greater));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
04_quicksort/csharp/05_quicksort/project.json
Normal file
19
04_quicksort/csharp/05_quicksort/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
04_quicksort/csharp/05_quicksort/project.lock.json
Normal file
6598
04_quicksort/csharp/05_quicksort/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
05_hash_tables/csharp/01_price_of_groceries/.gitignore
vendored
Normal file
2
05_hash_tables/csharp/01_price_of_groceries/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
05_hash_tables/csharp/01_price_of_groceries/.vscode/launch.json
vendored
Normal file
23
05_hash_tables/csharp/01_price_of_groceries/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_price_of_groceries.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
05_hash_tables/csharp/01_price_of_groceries/.vscode/tasks.json
vendored
Normal file
16
05_hash_tables/csharp/01_price_of_groceries/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
05_hash_tables/csharp/01_price_of_groceries/Program.cs
Normal file
20
05_hash_tables/csharp/01_price_of_groceries/Program.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var book = new Dictionary<string, decimal>();
|
||||
book.Add("apple", 0.67m);
|
||||
book.Add("milk", 1.49m);
|
||||
book.Add("avocado", 1.49m);
|
||||
foreach (var item in book)
|
||||
{
|
||||
Console.WriteLine($"{item.Key}: {item.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
05_hash_tables/csharp/01_price_of_groceries/project.json
Normal file
19
05_hash_tables/csharp/01_price_of_groceries/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
05_hash_tables/csharp/01_price_of_groceries/project.lock.json
Normal file
6598
05_hash_tables/csharp/01_price_of_groceries/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
05_hash_tables/csharp/02_check_voter/.gitignore
vendored
Normal file
2
05_hash_tables/csharp/02_check_voter/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
05_hash_tables/csharp/02_check_voter/.vscode/launch.json
vendored
Normal file
23
05_hash_tables/csharp/02_check_voter/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/02_check_voter.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
05_hash_tables/csharp/02_check_voter/.vscode/tasks.json
vendored
Normal file
16
05_hash_tables/csharp/02_check_voter/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
29
05_hash_tables/csharp/02_check_voter/Program.cs
Normal file
29
05_hash_tables/csharp/02_check_voter/Program.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static Dictionary<string, bool> _voted = new Dictionary<string, bool>();
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CheckVoter("tom");
|
||||
CheckVoter("mike");
|
||||
CheckVoter("mike");
|
||||
}
|
||||
|
||||
private static void CheckVoter(string name)
|
||||
{
|
||||
if (_voted.ContainsKey(name))
|
||||
{
|
||||
Console.WriteLine("kick them out!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_voted.Add(name, true);
|
||||
Console.WriteLine("let them vote!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
05_hash_tables/csharp/02_check_voter/project.json
Normal file
19
05_hash_tables/csharp/02_check_voter/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
05_hash_tables/csharp/02_check_voter/project.lock.json
Normal file
6598
05_hash_tables/csharp/02_check_voter/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
06_breadth-first_search/csharp/01_breadth_first_search/.gitignore
vendored
Normal file
2
06_breadth-first_search/csharp/01_breadth_first_search/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
06_breadth-first_search/csharp/01_breadth_first_search/.vscode/launch.json
vendored
Normal file
23
06_breadth-first_search/csharp/01_breadth_first_search/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_breadth_first_search.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
06_breadth-first_search/csharp/01_breadth_first_search/.vscode/tasks.json
vendored
Normal file
16
06_breadth-first_search/csharp/01_breadth_first_search/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static Dictionary<string, string[]> _graph = new Dictionary<string, string[]>();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
_graph.Add("you", new[] { "alice", "bob", "claire" });
|
||||
_graph.Add("bob", new[] { "anuj", "peggy" });
|
||||
_graph.Add("alice", new[] { "peggy" });
|
||||
_graph.Add("claire", new[] { "thom", "jonny" });
|
||||
_graph.Add("anuj", Array.Empty<string>());
|
||||
_graph.Add("peggy", Array.Empty<string>());
|
||||
_graph.Add("thom", Array.Empty<string>());
|
||||
_graph.Add("jonny", Array.Empty<string>());
|
||||
Search("you");
|
||||
}
|
||||
|
||||
private static bool Search(string name)
|
||||
{
|
||||
var searchQueue = new Queue<string>(_graph[name]);
|
||||
var searched = new List<string>();
|
||||
while (searchQueue.Any())
|
||||
{
|
||||
var person = searchQueue.Dequeue();
|
||||
if (!searched.Contains(person))
|
||||
{
|
||||
if (PersonIsSeller(person))
|
||||
{
|
||||
Console.WriteLine($"{person} is a mango seller");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
searchQueue = new Queue<string>(searchQueue.Concat(_graph[person]));
|
||||
searched.Add(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool PersonIsSeller(string name)
|
||||
{
|
||||
return name.EndsWith("m");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
2
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.gitignore
vendored
Normal file
2
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.vscode/launch.json
vendored
Normal file
23
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_dijkstras_algorithm.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.vscode/tasks.json
vendored
Normal file
16
07_dijkstras_algorithm/csharp/01_dijkstras_algorithm/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private const double _infinity = double.PositiveInfinity;
|
||||
private static Dictionary<string, Dictionary<string, double>> _graph = new Dictionary<string, Dictionary<string, double>>();
|
||||
private static List<string> _processed = new List<string>();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
_graph.Add("start", new Dictionary<string, double>());
|
||||
_graph["start"].Add("a", 6.0);
|
||||
_graph["start"].Add("b", 2.0);
|
||||
|
||||
_graph.Add("a", new Dictionary<string, double>());
|
||||
_graph["a"].Add("fin", 1.0);
|
||||
|
||||
_graph.Add("b", new Dictionary<string, double>());
|
||||
_graph["b"].Add("a", 3.0);
|
||||
_graph["b"].Add("fin", 5.0);
|
||||
|
||||
_graph.Add("fin", new Dictionary<string, double>());
|
||||
|
||||
var costs = new Dictionary<string, double>();
|
||||
costs.Add("a", 6.0);
|
||||
costs.Add("b", 2.0);
|
||||
costs.Add("fin", _infinity);
|
||||
|
||||
var parents = new Dictionary<string, string>();
|
||||
parents.Add("a", "start");
|
||||
parents.Add("b", "start");
|
||||
parents.Add("fin", null);
|
||||
|
||||
var node = FindLowestCostNode(costs);
|
||||
while (node != null)
|
||||
{
|
||||
var cost = costs[node];
|
||||
var neighbors = _graph[node];
|
||||
foreach (var n in neighbors.Keys)
|
||||
{
|
||||
var new_cost = cost + neighbors[n];
|
||||
if (costs[n] > new_cost)
|
||||
{
|
||||
costs[n] = new_cost;
|
||||
parents[n] = node;
|
||||
}
|
||||
}
|
||||
_processed.Add(node);
|
||||
node = FindLowestCostNode(costs);
|
||||
}
|
||||
Console.WriteLine(string.Join(", ", costs));
|
||||
}
|
||||
|
||||
private static string FindLowestCostNode(Dictionary<string, double> costs)
|
||||
{
|
||||
var lowestCost = double.PositiveInfinity;
|
||||
string lowestCostNode = null;
|
||||
foreach (var node in costs)
|
||||
{
|
||||
var cost = node.Value;
|
||||
if (cost < lowestCost && !_processed.Contains(node.Key))
|
||||
{
|
||||
lowestCost = cost;
|
||||
lowestCostNode = node.Key;
|
||||
}
|
||||
}
|
||||
return lowestCostNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
2
08_greedy_algorithms/csharp/01_set_covering/.gitignore
vendored
Normal file
2
08_greedy_algorithms/csharp/01_set_covering/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
08_greedy_algorithms/csharp/01_set_covering/.vscode/launch.json
vendored
Normal file
23
08_greedy_algorithms/csharp/01_set_covering/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_set_covering.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
08_greedy_algorithms/csharp/01_set_covering/.vscode/tasks.json
vendored
Normal file
16
08_greedy_algorithms/csharp/01_set_covering/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
37
08_greedy_algorithms/csharp/01_set_covering/Program.cs
Normal file
37
08_greedy_algorithms/csharp/01_set_covering/Program.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var statesNeeded = new HashSet<string> { "mt", "wa", "or", "id", "nv", "ut", "ca", "az" };
|
||||
var stations = new Dictionary<string, HashSet<string>>();
|
||||
stations.Add("kone", new HashSet<string> { "id", "nv", "ut" });
|
||||
stations.Add("ktwo", new HashSet<string> { "wa", "id", "mt" });
|
||||
stations.Add("kthree", new HashSet<string> { "or", "nv", "ca" });
|
||||
stations.Add("kfour", new HashSet<string> { "nv", "ut" });
|
||||
stations.Add("kfive", new HashSet<string> { "ca", "az" });
|
||||
var finalStations = new HashSet<string>();
|
||||
while (statesNeeded.Any())
|
||||
{
|
||||
string bestStation = null;
|
||||
var statesCovered = new HashSet<string>();
|
||||
foreach (var station in stations)
|
||||
{
|
||||
var covered = new HashSet<string>(statesNeeded.Intersect(station.Value));
|
||||
if (covered.Count > statesCovered.Count){
|
||||
bestStation = station.Key;
|
||||
statesCovered = covered;
|
||||
}
|
||||
}
|
||||
statesNeeded.RemoveWhere(s => statesCovered.Contains(s));
|
||||
finalStations.Add(bestStation);
|
||||
}
|
||||
Console.WriteLine(string.Join(", ", finalStations));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
08_greedy_algorithms/csharp/01_set_covering/project.json
Normal file
19
08_greedy_algorithms/csharp/01_set_covering/project.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
6598
08_greedy_algorithms/csharp/01_set_covering/project.lock.json
Normal file
6598
08_greedy_algorithms/csharp/01_set_covering/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
2
09_dynamic_programming/csharp/01_longest_common_subsequence/.gitignore
vendored
Normal file
2
09_dynamic_programming/csharp/01_longest_common_subsequence/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/bin/*
|
||||
**/obj/*
|
||||
23
09_dynamic_programming/csharp/01_longest_common_subsequence/.vscode/launch.json
vendored
Normal file
23
09_dynamic_programming/csharp/01_longest_common_subsequence/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/01_longest_common_subsequence.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"externalConsole": false,
|
||||
"stopAtEntry": false,
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command.pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
09_dynamic_programming/csharp/01_longest_common_subsequence/.vscode/tasks.json
vendored
Normal file
16
09_dynamic_programming/csharp/01_longest_common_subsequence/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/project.json"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
if (word_a[i] == word_b[1])
|
||||
{
|
||||
cell[i][j] = cell[i - 1][j - 1] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell[i][j] = Math.Max(cell[i - 1][j], cell[i][j - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user