forked from egonSchiele/grokking_algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add csharp examples (egonSchiele#10)
- Loading branch information
1 parent
c3396b8
commit 62ed616
Showing
96 changed files
with
107,024 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
01_introduction_to_algorithms/csharp/01_binary_search/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/bin/* | ||
**/obj/* |
23 changes: 23 additions & 0 deletions
23
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 16 additions & 0 deletions
16
01_introduction_to_algorithms/csharp/01_binary_search/.vscode/tasks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "0.1.0", | ||
"command": "dotnet", | ||
"isShellCommand": true, | ||
"args": [], | ||
"tasks": [ | ||
{ | ||
"taskName": "build", | ||
"args": [ | ||
"${workspaceRoot}/project.json" | ||
], | ||
"isBuildCommand": true, | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
39 changes: 39 additions & 0 deletions
39
01_introduction_to_algorithms/csharp/01_binary_search/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
01_introduction_to_algorithms/csharp/01_binary_search/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
Oops, something went wrong.