Compare commits
No commits in common. "68da0a4b6c723da0cb6f25a09a07906a4191291e" and "65d4126c7d654a865d02f9235a2a0e5d69e329e0" have entirely different histories.
68da0a4b6c
...
65d4126c7d
4 changed files with 0 additions and 83 deletions
|
@ -1,21 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
project(
|
|
||||||
Composite
|
|
||||||
VERSION 0.1.0
|
|
||||||
LANGUAGES CXX)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake")
|
|
||||||
|
|
||||||
include(ExportCompileCommands)
|
|
||||||
include(sccache)
|
|
||||||
|
|
||||||
add_executable(Composite main.cpp)
|
|
||||||
|
|
||||||
target_compile_features(Composite PUBLIC cxx_std_20)
|
|
||||||
|
|
||||||
set_target_properties(
|
|
||||||
Composite
|
|
||||||
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
|
|
|
@ -1 +0,0 @@
|
||||||
../scripts/bootstrap.sh
|
|
|
@ -1 +0,0 @@
|
||||||
../scripts/build.sh
|
|
|
@ -1,60 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Node {
|
|
||||||
public:
|
|
||||||
virtual ~Node() = default;
|
|
||||||
virtual void print() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class InnerNode : public Node {
|
|
||||||
private:
|
|
||||||
std::string name_;
|
|
||||||
std::vector<Node *> children_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
InnerNode(std::string_view name) : name_(name) {}
|
|
||||||
|
|
||||||
void addNode(Node *node) { children_.push_back(node); }
|
|
||||||
|
|
||||||
void print() const override {
|
|
||||||
std::cout << name_ << " (inner)" << std::endl;
|
|
||||||
|
|
||||||
for (auto child : children_) {
|
|
||||||
child->print();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Leaf : public Node {
|
|
||||||
private:
|
|
||||||
std::string name_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Leaf(std::string_view name) : name_(name) {}
|
|
||||||
|
|
||||||
void print() const override { std::cout << name_ << " (leaf)" << std::endl; }
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
|
|
||||||
std::cout << "Composite" << std::endl;
|
|
||||||
|
|
||||||
InnerNode tree("root");
|
|
||||||
InnerNode left("left"), right("right");
|
|
||||||
Leaf leaf1("leaf 1"), leaf2("leaf 2"), leaf3("leaf 3"), leaf4("leaf 4");
|
|
||||||
|
|
||||||
tree.addNode(&left);
|
|
||||||
tree.addNode(&right);
|
|
||||||
|
|
||||||
left.addNode(&leaf1);
|
|
||||||
left.addNode(&leaf2);
|
|
||||||
|
|
||||||
right.addNode(&leaf3);
|
|
||||||
right.addNode(&leaf4);
|
|
||||||
|
|
||||||
tree.print();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue