tree structure

main
syneffort 2 years ago
parent c640109d43
commit 7d135de61c
  1. 19
      .vscode/launch.json
  2. 6
      .vscode/tasks.json
  3. 17
      DataStructure/treeStructure/BinaryTree.cs
  4. 14
      DataStructure/treeStructure/BinaryTreeNode.cs
  5. 16
      DataStructure/treeStructure/Program.cs

@ -8,7 +8,24 @@
// Use IntelliSense to find out which attributes exist for C# debugging // Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes // Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md // 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", "type": "coreclr",
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",

@ -7,7 +7,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"build", "build",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj", "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary" "/consoleloggerparameters:NoSummary"
], ],
@ -19,7 +19,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"publish", "publish",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj", "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary" "/consoleloggerparameters:NoSummary"
], ],
@ -33,7 +33,7 @@
"watch", "watch",
"run", "run",
"--project", "--project",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj" "${workspaceFolder}/DataStructure/treeStructure/treeStructure.csproj"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
} }

@ -0,0 +1,17 @@
namespace treeStructure
{
class BinaryTree<T>
{
public BinaryTreeNode<T>? Root { get; set; }
public void PreOrderTraversal(BinaryTreeNode<T> node)
{
if (node == null)
return;
System.Console.WriteLine(node.Data);
PreOrderTraversal(node.Left);
PreOrderTraversal(node.Right);
}
}
}

@ -0,0 +1,14 @@
namespace treeStructure
{
class BinaryTreeNode<T>
{
public T Data { get; set; }
public BinaryTreeNode<T>? Left { get; set; }
public BinaryTreeNode<T>? Right { get; set; }
public BinaryTreeNode(T data)
{
this.Data = data;
}
}
}

@ -0,0 +1,16 @@
namespace treeStructure
{
static class Program
{
static void Main(string[] args)
{
BinaryTree<int> btree = new BinaryTree<int>();
btree.Root = new BinaryTreeNode<int>(1);
btree.Root.Left = new BinaryTreeNode<int>(2);
btree.Root.Right = new BinaryTreeNode<int>(3);
btree.Root.Left.Left = new BinaryTreeNode<int>(4);
btree.PreOrderTraversal(btree.Root);
}
}
}
Loading…
Cancel
Save