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