add csharp examples (#10)
This commit is contained in:
committed by
Aditya Bhargava
parent
c3396b8b0a
commit
62ed616954
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
Reference in New Issue
Block a user