Initial commit

This commit is contained in:
Mikołaj Rosa 2022-05-30 15:28:29 +02:00
commit 2cf9d4a427
10 changed files with 329 additions and 0 deletions

BIN
desktop.ini Normal file

Binary file not shown.

BIN
drzewa binarne BST.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31105.61
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BST", "BST\BST.vcxproj", "{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x64.ActiveCfg = Debug|x64
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x64.Build.0 = Debug|x64
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x86.ActiveCfg = Debug|Win32
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Debug|x86.Build.0 = Debug|Win32
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x64.ActiveCfg = Release|x64
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x64.Build.0 = Release|x64
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x86.ActiveCfg = Release|Win32
{BE026CE1-51B4-49E7-82A7-B84B9849E3A2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E9400436-F9FC-425A-98F3-10BFDFEDECE1}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,67 @@
#include <iostream>
#include "BST.h"
using namespace std;
BST::BST():root(NULL) {}
BST::BST(int tab[], int size) {
for (int i = 0; i < size; i++)
insert(root, tab[i]);
}
bool BST::insert(BSTNode*& node, int wartosc) {
if (node == NULL) { // tworzymy i dołączamy węzeł
node = new BSTNode;
node->data = wartosc;
node->left = NULL;
node->right = NULL;
return true;
}
else
if (wartosc < node->data) return insert(node->left, wartosc); // rekurencyjne wywolanie
else
if (wartosc > node->data) return insert(node->right, wartosc); // rekurencyjne wywolanie
// uwaga: liczby powtarzające się nie są dodawane do drzewa
return false;
}
//BSTNode* BST::search(int key) {}
//BSTNode* BST::search(BSTNode* node, int key) {}
//int BST::minKey() {}
//int BST::minKey(BSTNode* node) {}
//int BST::maxKey() {}
//void BST::inorder(BSTNode* x) {}
//void BST::preorder(BSTNode* x) {}
//void BST::postorder(BSTNode* x) {}
void BST::print(BSTNode* x){
if (!x->left && !x->right) return;
cout << x->data << " : lewy-> ";
if (x->left) cout << x->left->data;
else cout << "NULL";
cout << ", prawy-> ";
if (x->right) cout << x->right->data;
else cout << "NULL";
cout << endl;
if (x->left) print(x->left);
if (x->right) print(x->right);
}
void BST::remove(BSTNode* x) {
if (!x) return;
remove(x->left);
remove(x->right);
cout << "usuwam " << x->data << endl;
delete x;
}

View File

@ -0,0 +1,32 @@
#pragma once
class BSTNode {
public:
int data;
BSTNode* left, * right;
};
class BST
{
public:
BSTNode* root; // korzeń drzewa
BST();
BST(int T[], int size); //tworzy drzewo na podstawie tablicy
~BST() { remove(root); }; //usuwa drzewo, zwalnia pamięć
bool insert(BSTNode*& node, int wartosc); //zwraca true - wezęł dodany, false-węzeł już jest
void remove(BSTNode* x); //usuwa poddrzewa o korzeniu w x
BSTNode* search(int key); //zwraca wsk. na węzeł zawierający klucz key lub
//NULL, jeśli drzewo BST nie posiada takiego węzła.
int maxKey();
int minKey();
BSTNode* search(BSTNode* node, int key);
int minKey(BSTNode*);
void inorder(BSTNode* x);
void preorder(BSTNode* x);
void postorder(BSTNode* x);
void print(BSTNode* );
};

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{be026ce1-51b4-49e7-82a7-b84b9849e3a2}</ProjectGuid>
<RootNamespace>BST</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="BST.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BST.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Pliki źródłowe">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Pliki nagłówkowe">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Pliki zasobów">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BST.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Pliki źródłowe</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BST.h">
<Filter>Pliki nagłówkowe</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,14 @@
#include <iostream>
#include "BST.h"
using namespace std;
int main()
{
int dane[]{ 8, 3, 6, 1, 7, 10, 0, 2, 11, 4, 9 }; //{ 10,6,15,1,8,12,16,0,2,7,9 };
BST drzewo(dane, size(dane));
drzewo.print(drzewo.root);
cout << endl;
return 0;
}

Binary file not shown.