diff --git a/.vscode/launch.json b/.vscode/launch.json index de76b07..834caad 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,23 @@ // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요. "version": "0.2.0", "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": "graphStructure (Console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/DataStructure/graphStructure/bin/Debug/net7.0/graphStructure.dll", + "args": [], + "cwd": "${workspaceFolder}/DataStructure/graphStructure", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { // Use IntelliSense to find out which attributes exist for C# debugging // Use hover for the description of the existing attributes diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 36681ee..a730df7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj", + "${workspaceFolder}/DataStructure/graphStructure/graphStructure.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -33,7 +33,7 @@ "watch", "run", "--project", - "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj" + "${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj" ], "problemMatcher": "$msCompile" } diff --git a/DataStructure/graphStructure/Program.cs b/DataStructure/graphStructure/Program.cs index 3751555..04def45 100644 --- a/DataStructure/graphStructure/Program.cs +++ b/DataStructure/graphStructure/Program.cs @@ -1,2 +1,12 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using MainNamespace.Structure; + +namespace MainNamespace +{ + static class Program + { + static void Main(string[] args) + { + GraphClient.DoWork(); + } + } +} \ No newline at end of file diff --git a/DataStructure/graphStructure/Structure/Graph.cs b/DataStructure/graphStructure/Structure/Graph.cs new file mode 100644 index 0000000..ba0ddd2 --- /dev/null +++ b/DataStructure/graphStructure/Structure/Graph.cs @@ -0,0 +1,51 @@ +namespace MainNamespace.Structure +{ + class Graph + { + private List> _nodeList; + + public Graph() + { + _nodeList = new List>(); + } + + public GraphNode AddNode(T data) + { + GraphNode node = new GraphNode(data); + _nodeList.Add(node); + return node; + } + + public GraphNode AddNode(GraphNode node) + { + _nodeList.Add(node); + return node; + } + + public void AddEdge(GraphNode from, GraphNode to, bool oneway = true, int weight = 0) + { + from.Neighbors.Add(to); + from.Weights.Add(weight); + + if (!oneway) + { + to.Neighbors.Add(from); + to.Weights.Add(weight); + } + } + + internal void DebugPrintLinks() + { + foreach (var node in _nodeList) + { + for (int i = 0; i < node.Neighbors.Count; i++) + { + var neighbor = node.Neighbors[i]; + var weight = node.Weights[i]; + + System.Console.WriteLine($"[{node.Data}] ---{weight}--- [{neighbor.Data}]"); + } + } + } + } +} \ No newline at end of file diff --git a/DataStructure/graphStructure/Structure/GraphClient.cs b/DataStructure/graphStructure/Structure/GraphClient.cs new file mode 100644 index 0000000..e35845f --- /dev/null +++ b/DataStructure/graphStructure/Structure/GraphClient.cs @@ -0,0 +1,23 @@ +namespace MainNamespace.Structure +{ + class GraphClient + { + public static void DoWork() + { + Graph g = new Graph(); + + var n1 = g.AddNode(10); + var n2 = g.AddNode(20); + var n3 = g.AddNode(30); + var n4 = g.AddNode(40); + var n5 = g.AddNode(50); + + g.AddEdge(n1, n3, true, 1); + g.AddEdge(n2, n4, true, 2); + g.AddEdge(n3, n4, true, 3); + g.AddEdge(n3, n5, true, 10); + + g.DebugPrintLinks(); + } + } +} \ No newline at end of file diff --git a/DataStructure/graphStructure/Structure/GraphNode.cs b/DataStructure/graphStructure/Structure/GraphNode.cs new file mode 100644 index 0000000..96fb05e --- /dev/null +++ b/DataStructure/graphStructure/Structure/GraphNode.cs @@ -0,0 +1,40 @@ +namespace MainNamespace.Structure +{ + class GraphNode + { + private List>? _neighbors; + private List? _weights; + + public T? Data { get; set; } + + public GraphNode() + { + + } + + public GraphNode(T data) + { + this.Data = data; + } + + public List> Neighbors + { + get + { + _neighbors = _neighbors ?? new List>(); + + return _neighbors; + } + } + + public List Weights + { + get + { + _weights = _weights ?? new List(); + + return _weights; + } + } + } +} \ No newline at end of file