Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions Ch 4. Trees and Graphs /C++14/4.11-RandomNode.cpp

This file was deleted.

127 changes: 0 additions & 127 deletions Ch 4. Trees and Graphs /C++14/4.11m-RandomTree.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions Ch 4. Trees and Graphs /C++14/4.12-PathsWithSum.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions Ch 4. Trees and Graphs /C++14/4.8-FirstCommonAncestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
enum FindResult
{
NotFound, // node not found in subtree
FoundLeft, // node found in left subtree
FoundRight, // node found in right subtree
FoundLeft, // node not found in left subtree
FoundRight, // node not found in right subtree
FoundEqual // node is subtree root
};

Expand Down
5 changes: 2 additions & 3 deletions Ch 4. Trees and Graphs /C++14/tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

#include "treenode.hpp"

template <typename T, bool WithParent = false,
template<typename, bool> class N = Node>
template <typename T, bool NodeWithParent = false>
class Tree
{
public:
using NodePtr = typename N<T, WithParent>::NodePtr;
using NodePtr = typename Node<T, NodeWithParent>::NodePtr;

const NodePtr &getRoot() const
{
Expand Down
29 changes: 14 additions & 15 deletions Ch 4. Trees and Graphs /C++14/treenodeiterator.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include <stack>
#include <memory>
#include "treenode.hpp"

template <typename Iterator, typename T, bool NodeWithParent,
template <typename, bool> class Node>
template <typename Iterator, typename T, bool NodeWithParent>
class IteratorBase
{
using NodePtr = typename Node<T, NodeWithParent>::NodePtr;
Expand Down Expand Up @@ -38,8 +37,8 @@ class IteratorBase
std::weak_ptr<Node<T, NodeWithParent>> currNode;
};

template <typename Iterator, typename T, template <typename, bool> class Node>
class IteratorBase<Iterator, T, false, Node>
template <typename Iterator, typename T>
class IteratorBase<Iterator, T, false>
{
using NodePtr = std::shared_ptr<Node<T, false>>;

Expand Down Expand Up @@ -82,10 +81,10 @@ class IteratorBase<Iterator, T, false, Node>
std::stack<NodePtr> parents;
};

template <typename T, bool NodeWithParent, template <typename, bool> class Node>
class Iterator : public IteratorBase<Iterator<T, NodeWithParent, Node>, T, NodeWithParent, Node>
template <typename T, bool NodeWithParent>
class Iterator : public IteratorBase<Iterator<T, NodeWithParent>, T, NodeWithParent>
{
using Super = IteratorBase<Iterator<T, NodeWithParent, Node>, T, NodeWithParent, Node>;
using Super = IteratorBase<Iterator<T, NodeWithParent>, T, NodeWithParent>;
using NodePtr = typename Node<T, NodeWithParent>::NodePtr;

public:
Expand All @@ -106,17 +105,17 @@ class Iterator : public IteratorBase<Iterator<T, NodeWithParent, Node>, T, NodeW
}
};

template <typename T, bool NodeWithParent, template <typename, bool> class Node>
template <typename T, bool NodeWithParent>
class Tree;

template <typename T, bool NodeWithParent, template <typename, bool> class Node>
auto begin(const Tree<T, NodeWithParent, Node> &tree)
template <typename T, bool NodeWithParent>
auto begin(const Tree<T, NodeWithParent> &tree)
{
return Iterator<T, NodeWithParent, Node>(tree.getRoot());
return Iterator<T, NodeWithParent>(tree.getRoot());
}

template <typename T, bool NodeWithParent, template <typename, bool> class Node>
auto end(const Tree<T, NodeWithParent, Node>)
template <typename T, bool NodeWithParent>
auto end(const Tree<T, NodeWithParent>)
{
return Iterator<T, NodeWithParent, Node>();
return Iterator<T, NodeWithParent>();
}
Loading