diff --git a/.vscode/launch.json b/.vscode/launch.json index 33b65f8..de76b07 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,24 @@ // 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": ".NET Core Launch (console)", + "name": "treeStructure (Console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/DataStructure/treeStructure/bin/Debug/net7.0/treeStructure.dll", + "args": [], + "cwd": "${workspaceFolder}/DataStructure/treeStructure", + // 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 + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": "hashTableStructure (Console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a7cb9aa..36681ee 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj", + "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -19,7 +19,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj", + "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -33,7 +33,7 @@ "watch", "run", "--project", - "${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj" + "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj" ], "problemMatcher": "$msCompile" } diff --git a/DataStructure/treeStructure/BinaryTree.cs b/DataStructure/treeStructure/BinaryTree.cs new file mode 100644 index 0000000..5d5274d --- /dev/null +++ b/DataStructure/treeStructure/BinaryTree.cs @@ -0,0 +1,17 @@ +namespace treeStructure +{ + class BinaryTree + { + public BinaryTreeNode? Root { get; set; } + + public void PreOrderTraversal(BinaryTreeNode node) + { + if (node == null) + return; + + System.Console.WriteLine(node.Data); + PreOrderTraversal(node.Left); + PreOrderTraversal(node.Right); + } + } +} \ No newline at end of file diff --git a/DataStructure/treeStructure/BinaryTreeNode.cs b/DataStructure/treeStructure/BinaryTreeNode.cs new file mode 100644 index 0000000..f5f36c4 --- /dev/null +++ b/DataStructure/treeStructure/BinaryTreeNode.cs @@ -0,0 +1,14 @@ +namespace treeStructure +{ + class BinaryTreeNode + { + public T Data { get; set; } + public BinaryTreeNode? Left { get; set; } + public BinaryTreeNode? Right { get; set; } + + public BinaryTreeNode(T data) + { + this.Data = data; + } + } +} \ No newline at end of file diff --git a/DataStructure/treeStructure/Program.cs b/DataStructure/treeStructure/Program.cs new file mode 100644 index 0000000..9da4b45 --- /dev/null +++ b/DataStructure/treeStructure/Program.cs @@ -0,0 +1,16 @@ +namespace treeStructure +{ + static class Program + { + static void Main(string[] args) + { + BinaryTree btree = new BinaryTree(); + btree.Root = new BinaryTreeNode(1); + btree.Root.Left = new BinaryTreeNode(2); + btree.Root.Right = new BinaryTreeNode(3); + btree.Root.Left.Left = new BinaryTreeNode(4); + + btree.PreOrderTraversal(btree.Root); + } + } +} \ No newline at end of file