Giter Site home page Giter Site logo

cpp-ex4's Introduction

Trees in C++

Build Status License

Table of Contents

Overview

This repository contains a C++ implementation of binary and n-ary (n >= 2) tree data structures, along with functionalities for adding nodes, performing traversals (pre-order, post-order, in-order, BFS, DFS), and printing the tree structure.

The printing operator for trees launches a window with a GUI that displays the tree in its original form. (Uses SFML)

GUI Example:

image

The project is fully backed with testing cases to cover various scenarios. The makefile includes options for memory leak checking using tools like valgrind.

Features

  • Supports storing different data types in the tree nodes (e.g., integers, strings).
  • Handles binary and n-ary tree structures (n >= 2).
  • Provides a clear visual representation of the tree structure when printed.
  • Implements different tree traversal methods for various use cases.

Usage

// Binary tree
Node<double> root_node = Node<double>(1.1);
Tree<double> tree; // Binary tree that contains doubles.
tree.add_root(root_node);
Node<double> n1 = Node<double>(1.2);
Node<double> n2 = Node<double>(1.3);
Node<double> n3 = Node<double>(1.4);
Node<double> n4 = Node<double>(1.5);
Node<double> n5 = Node<double>(1.6);   
tree.add_sub_node(root_node, n1);
tree.add_sub_node(root_node, n2);
tree.add_sub_node(n1, n3);
tree.add_sub_node(n1, n4);
tree.add_sub_node(n2, n5);
//tree.add_sub_node(root_node, n3); // This should throw an exception.
cout << tree;

This code displays the following GUI window: image

The second argument of tree initialization sets the tree's maximum degree (K):

Tree<T, K> tree;

By default, it is set to be binary (K=2).

cpp-ex4's People

Contributors

avihyb avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.