summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tree/.cproject4
-rw-r--r--tree/.settings/language.settings.xml4
-rw-r--r--tree/Debug/makefile118
-rw-r--r--tree/Debug/sources.mk50
-rw-r--r--tree/Debug/src/subdir.mk42
-rw-r--r--tree/src/cTree.cpp3
-rw-r--r--tree/src/main.cpp72
7 files changed, 165 insertions, 128 deletions
diff --git a/tree/.cproject b/tree/.cproject
index b85822e..9a5d181 100644
--- a/tree/.cproject
+++ b/tree/.cproject
@@ -9,8 +9,6 @@
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
- <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
@@ -18,7 +16,7 @@
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.992883527." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.1750761033" name="Cross GCC" nonInternalBuilderId="cdt.managedbuild.builder.gnu.cross" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1864634322" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
- <builder buildPath="${workspace_loc:/tree}/Debug" id="cdt.managedbuild.builder.gnu.cross.522892350" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.builder.gnu.cross"/>
+ <builder autoBuildTarget="all" buildPath="${workspace_loc:/tree}/Debug" cleanBuildTarget="clean" id="org.eclipse.cdt.build.core.internal.builder.192922103" incrementalBuildTarget="all" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1925147654" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1319784671" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.649809700" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
diff --git a/tree/.settings/language.settings.xml b/tree/.settings/language.settings.xml
index 0d521f3..4200ffe 100644
--- a/tree/.settings/language.settings.xml
+++ b/tree/.settings/language.settings.xml
@@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903827296288134848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-526476468772666232" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903827296288134848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-526476468772666232" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
diff --git a/tree/Debug/makefile b/tree/Debug/makefile
index beab843..707ea55 100644
--- a/tree/Debug/makefile
+++ b/tree/Debug/makefile
@@ -1,59 +1,59 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
--include ../makefile.init
-
-RM := rm -rf
-
-# All of the sources participating in the build are defined here
--include sources.mk
--include src/subdir.mk
--include subdir.mk
--include objects.mk
-
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(strip $(CC_DEPS)),)
--include $(CC_DEPS)
-endif
-ifneq ($(strip $(C++_DEPS)),)
--include $(C++_DEPS)
-endif
-ifneq ($(strip $(C_UPPER_DEPS)),)
--include $(C_UPPER_DEPS)
-endif
-ifneq ($(strip $(CXX_DEPS)),)
--include $(CXX_DEPS)
-endif
-ifneq ($(strip $(C_DEPS)),)
--include $(C_DEPS)
-endif
-ifneq ($(strip $(CPP_DEPS)),)
--include $(CPP_DEPS)
-endif
-endif
-
--include ../makefile.defs
-
-# Add inputs and outputs from these tool invocations to the build variables
-
-# All Target
-all: tree
-
-# Tool invocations
-tree: $(OBJS) $(USER_OBJS)
- @echo 'Building target: $@'
- @echo 'Invoking: Cross G++ Linker'
- g++ -o "tree" $(OBJS) $(USER_OBJS) $(LIBS)
- @echo 'Finished building target: $@'
- @echo ' '
-
-# Other Targets
-clean:
- -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) tree
- -@echo ' '
-
-.PHONY: all clean dependents
-.SECONDARY:
-
--include ../makefile.targets
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+-include ../makefile.init
+
+RM := rm -rf
+
+# All of the sources participating in the build are defined here
+-include sources.mk
+-include src/subdir.mk
+-include subdir.mk
+-include objects.mk
+
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(strip $(CC_DEPS)),)
+-include $(CC_DEPS)
+endif
+ifneq ($(strip $(C++_DEPS)),)
+-include $(C++_DEPS)
+endif
+ifneq ($(strip $(C_UPPER_DEPS)),)
+-include $(C_UPPER_DEPS)
+endif
+ifneq ($(strip $(CXX_DEPS)),)
+-include $(CXX_DEPS)
+endif
+ifneq ($(strip $(C_DEPS)),)
+-include $(C_DEPS)
+endif
+ifneq ($(strip $(CPP_DEPS)),)
+-include $(CPP_DEPS)
+endif
+endif
+
+-include ../makefile.defs
+
+# Add inputs and outputs from these tool invocations to the build variables
+
+# All Target
+all: tree
+
+# Tool invocations
+tree: $(OBJS) $(USER_OBJS)
+ @echo 'Building target: $@'
+ @echo 'Invoking: Cross G++ Linker'
+ g++ -o "tree" $(OBJS) $(USER_OBJS) $(LIBS)
+ @echo 'Finished building target: $@'
+ @echo ' '
+
+# Other Targets
+clean:
+ -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) tree
+ -@echo ' '
+
+.PHONY: all clean dependents
+.SECONDARY:
+
+-include ../makefile.targets
diff --git a/tree/Debug/sources.mk b/tree/Debug/sources.mk
index f9fe80f..2291deb 100644
--- a/tree/Debug/sources.mk
+++ b/tree/Debug/sources.mk
@@ -1,27 +1,27 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-C_UPPER_SRCS :=
-CXX_SRCS :=
-C++_SRCS :=
-OBJ_SRCS :=
-CC_SRCS :=
-ASM_SRCS :=
-C_SRCS :=
-CPP_SRCS :=
-O_SRCS :=
-S_UPPER_SRCS :=
-CC_DEPS :=
-C++_DEPS :=
-EXECUTABLES :=
-OBJS :=
-C_UPPER_DEPS :=
-CXX_DEPS :=
-C_DEPS :=
-CPP_DEPS :=
-
-# Every subdirectory with source files must be described here
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+C_UPPER_SRCS :=
+CXX_SRCS :=
+C++_SRCS :=
+OBJ_SRCS :=
+CC_SRCS :=
+ASM_SRCS :=
+C_SRCS :=
+CPP_SRCS :=
+O_SRCS :=
+S_UPPER_SRCS :=
+CC_DEPS :=
+C++_DEPS :=
+EXECUTABLES :=
+OBJS :=
+C_UPPER_DEPS :=
+CXX_DEPS :=
+C_DEPS :=
+CPP_DEPS :=
+
+# Every subdirectory with source files must be described here
SUBDIRS := \
src \
-
+
diff --git a/tree/Debug/src/subdir.mk b/tree/Debug/src/subdir.mk
index 24d177a..e0e45bf 100644
--- a/tree/Debug/src/subdir.mk
+++ b/tree/Debug/src/subdir.mk
@@ -1,33 +1,33 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../src/cData.cpp \
../src/cNode.cpp \
../src/cTree.cpp \
-../src/main.cpp
-
+../src/main.cpp
+
OBJS += \
./src/cData.o \
./src/cNode.o \
./src/cTree.o \
-./src/main.o
-
+./src/main.o
+
CPP_DEPS += \
./src/cData.d \
./src/cNode.d \
./src/cTree.d \
-./src/main.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/%.o: ../src/%.cpp
- @echo 'Building file: $<'
- @echo 'Invoking: Cross G++ Compiler'
- g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
- @echo 'Finished building: $<'
- @echo ' '
-
-
+./src/main.d
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/%.o: ../src/%.cpp
+ @echo 'Building file: $<'
+ @echo 'Invoking: Cross G++ Compiler'
+ g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
+ @echo 'Finished building: $<'
+ @echo ' '
+
+
diff --git a/tree/src/cTree.cpp b/tree/src/cTree.cpp
index f4fcf9a..943819c 100644
--- a/tree/src/cTree.cpp
+++ b/tree/src/cTree.cpp
@@ -104,6 +104,9 @@ unsigned int cTree::depth()
unsigned int cTree::gradeOfUnbalance()
{
+ if(root->getSubtreeSize() == 0)
+ return 0;
+
double minDepth = log2(size());
unsigned int iDepth = depth();
diff --git a/tree/src/main.cpp b/tree/src/main.cpp
index 10534f3..55709ff 100644
--- a/tree/src/main.cpp
+++ b/tree/src/main.cpp
@@ -4,6 +4,7 @@
* Created on: Jan 25, 2017
* Author: jonas
*/
+
#include <iostream>
#include <string>
#include <sstream>
@@ -13,53 +14,73 @@ using namespace std;
cTree* a;
-void fill()
-{
- for (char b = ' '; b <= '~'; b++) //insert some data into tree
- {
- for(char c = ' '; c<= '~'; c++)
- {
- stringstream ss;
- ss << b;
- ss << c;
-
- a->insert(ss.str());
- }
- }
-}
+void fill(void);
int main (void)
{
a = new cTree();
+ int i;
int iInputOption;
+ string s;
+
+ cout << endl;
+ cout << "| |" << endl;
+ cout << "| |_ _ __ ___ ___ " << endl;
+ cout << "| __| '__/ _ \\/ _ \\" << endl;
+ cout << "| |_| | | __/ __/" << endl;
+ cout << " \\__|_| \\___|\\___|" << endl << endl;
+
while (1)
{
+ cout << "===========================\n";
cout << "[1] Fill with Data\n";
cout << "[2] Clear\n";
cout << "[3] Balance\n";
cout << "[4] Draw\n";
cout << "[5] Info\n";
+ cout << "[6] Insert\n";
+ cout << "[7] Remove\n";
+ cout << "[8] Get by Inorder ID\n";
+ cout << "[0] Exit\n";
cout << "> ";
cin >> iInputOption;
switch(iInputOption)
{
- case 1:
+ case 1: //fill
cout << "Filling with Data.....";
fill();
cout << "OK\n";
break;
- case 2:
+ case 2: //clear
a->clear();
break;
- case 3:
+ case 3: //balance
a->sort();
break;
- case 4:
+ case 4: //draw
a->draw();
break;
+ case 5: //Info
+ cout << "Size: " << a->size() << ", Depth: " << a->depth() << ", Unbalance: " << a->gradeOfUnbalance() << endl << endl;
+ break;
+ case 6: //Insert
+ cout << "Insert: ";
+ cin >> s;
+ a->insert(s);
+ break;
+ case 7: //Remove
+ cout << "ID to remove: ";
+ cin >> i;
+ a->remove((*a)[i]);
+ break;
+ case 8: //get by ID
+ cout << "ID to get: ";
+ cin >> i;
+ cout << i << ": " << (*a)[i]->getData() << endl;
+ break;
default:
cout << "Unrecognized Command\n";
break;
@@ -70,5 +91,20 @@ int main (void)
return 0;
}
+void fill(void)
+{
+ for (char b = ' '; b <= '~'; b++) //insert some data into tree
+ {
+ for(char c = ' '; c<= '~'; c++)
+ {
+ stringstream ss;
+ ss << b;
+ ss << c;
+
+ a->insert(ss.str());
+ }
+ }
+}
+