Skip to content
Snippets Groups Projects
Commit 9f0bfa13 authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

DoubleLinked, BinTree

parent beddf116
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P08 CycleList", "P08 CycleL ...@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P08 CycleList", "P08 CycleL
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P09 DoubleLinkedList", "P09 DoubleLinkedList\P09 DoubleLinkedList.csproj", "{700D8B3A-C742-4E1C-A550-33730D987C57}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P09 DoubleLinkedList", "P09 DoubleLinkedList\P09 DoubleLinkedList.csproj", "{700D8B3A-C742-4E1C-A550-33730D987C57}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P10 BinTree", "P10 BinTree\P10 BinTree.csproj", "{CE6BBA02-59C6-4A56-9867-1F49C451CFBB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -63,6 +65,10 @@ Global ...@@ -63,6 +65,10 @@ Global
{700D8B3A-C742-4E1C-A550-33730D987C57}.Debug|Any CPU.Build.0 = Debug|Any CPU {700D8B3A-C742-4E1C-A550-33730D987C57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{700D8B3A-C742-4E1C-A550-33730D987C57}.Release|Any CPU.ActiveCfg = Release|Any CPU {700D8B3A-C742-4E1C-A550-33730D987C57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{700D8B3A-C742-4E1C-A550-33730D987C57}.Release|Any CPU.Build.0 = Release|Any CPU {700D8B3A-C742-4E1C-A550-33730D987C57}.Release|Any CPU.Build.0 = Release|Any CPU
{CE6BBA02-59C6-4A56-9867-1F49C451CFBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE6BBA02-59C6-4A56-9867-1F49C451CFBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE6BBA02-59C6-4A56-9867-1F49C451CFBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE6BBA02-59C6-4A56-9867-1F49C451CFBB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>P10_BinTree</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

namespace P10_BinTree
{
class BTree
{
class LItem
{
public int number;
public LItem? left = null, right = null;
public LItem(int number)
{
this.number = number;
}
public void Print()
{
left?.Print();
Console.Write($"{number} - ");
right?.Print();
}
}
LItem? root = null;
public void Add(int number)
{
LItem? neu = new LItem(number);
if (root == null)
root = neu;
else
{
var tmp = root;
while (true)
{
if (number < tmp.number) // gehört die Zahl auf die linke Seite?
{
if (tmp.left == null) // linker Parkplatz frei?
{
tmp.left = neu;
break;
}
else
tmp = tmp.left;
} // analog für die rechte Seite
else
{
if (tmp.right == null) // rechter Parkplatz frei?
{
tmp.right = neu;
break;
}
else
tmp = tmp.right;
}
}
}
}
public void Print()
{
root?.Print();
}
}
class Program
{
static void Main(string[] args)
{
BTree bt = new BTree();
bt.Add(50);
bt.Add(30);
bt.Add(70);
bt.Add(60);
bt.Add(50);
bt.Add(65);
bt.Print();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment