Language: C++

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

template<class T>
class BinaryTree {
public:
	class Node {
	public:
		int parent = -1;
		int left;
		int right;

		T value;
	};

	vector<Node> data;
	int root = -1;
	int _size = 1;

	BinaryTree() {
		data.resize(1);
	}

	Node operator[](int id) {
		return data[id];
	}

	void resize(int size) {
		if (size > _size) {
			while (_size < size) {
				_size *= 2;
			}
			data.resize(_size);
		}
	}

	void addNode(int id, int left, int right, T value) {
		resize(id + 1);

		if (root == -1) {
			root = id;
			data[id].parent = -1;
		}

		data[id].left = left;
		data[id].right = right;
		data[id].value = value;

		resize(left + 1);
		if (left != -1)
			data[left].parent = id;
		resize(right + 1);
		if (right != -1)
			data[right].parent = id;

		if (root == left || root == right) {
			while (data[root].parent != -1) {
				root = data[root].parent;
			}
		}
	}

	int getSibling(int id) {
		if (data[id].parent == -1)
			return -1;

		int parent = data[id].parent;
		if (data[parent].left == id)
			return data[parent].right;
		if (data[parent].right == id)
			return data[parent].left;
	}

	int getDegree(int id) {
		int degree = 0;
		if (data[id].left != -1)
			degree++;
		if (data[id].right != -1)
			degree++;

		return degree;
	}

	int getDepth(int id) {
		return recurDepth(id, 0);
	}

	int recurDepth(int id) {
		int depth = 0;
		while (data[id].parent != -1) {
			id = data[id].parent;
			depth++;
		}
		return depth;
	}

	int getHeight(int id) {
		int h1 = -1, h2 = -1;
		if (data[id].left != -1)
			h1 = getHeight(data[id].left);
		if (data[id].right != -1)
			h2 = getHeight(data[id].right);

		return max(h1, h2) + 1;
	}

	string getName(int id) {
		if (data[id].parent == -1)
			return "root";
		else if (data[id].left == -1 && data[id].right == -1)
			return "leaf";

		return "internal node";
	}

	vector<int> getPreOrder() {
		vector<int> dst;
		calcPreOrder(dst, root);
		return dst;
	}

	void calcPreOrder(vector<int>& order, int id) {
		order.push_back(id);
		if (data[id].left != -1)
			calcPreOrder(order, data[id].left);
		if (data[id].right != -1)
			calcPreOrder(order, data[id].right);
	}

	vector<int> getInOrder() {
		vector<int> dst;
		calcInOrder(dst, root);
		return dst;
	}

	void calcInOrder(vector<int>& order, int id) {
		if (data[id].left != -1)
			calcInOrder(order, data[id].left);
		order.push_back(id);
		if (data[id].right != -1)
			calcInOrder(order, data[id].right);
	}

	vector<int> getPostOrder() {
		vector<int> dst;
		calcPostOrder(dst, root);
		return dst;
	}

	void calcPostOrder(vector<int>& order, int id) {
		if (data[id].left != -1)
			calcPostOrder(order, data[id].left);
		if (data[id].right != -1)
			calcPostOrder(order, data[id].right);
		order.push_back(id);
	}
};

template<class T>
void printVector(vector<T>& v, int mode) {
	if (mode == 0) {
		for (int i = 0, k = v.size(); i < k; ++i) {
			cout << v[i];
			if (i < k - 1)
				cout << " ";
		}
		cout << endl;
	}
	else if (mode == 1) {
		for (int i = 0, k = v.size(); i < k; ++i) {
			cout << v[i] << endl;
		}
	}
}

int main() {
	BinaryTree<int> tree;
	int n, id, l, r;
	cin >> n;
	while (n--) {
		cin >> id >> l >> r;
		tree.addNode(id, l, r, 0);
	}

	cout << "Preorder" << endl;
	printVector(tree.getPreOrder(), 0);
	cout << "Inorder" << endl;
	printVector(tree.getInOrder(), 0);
	cout << "PostOrder" << endl;
	printVector(tree.getPostOrder(), 0);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:228:37: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
  228 |         printVector(tree.getPreOrder(), 0);
      |                     ~~~~~~~~~~~~~~~~^~
a.cc:202:29: note:   initializing argument 1 of 'void printVector(std::vector<_Tp>&, int) [with T = int]'
  202 | void printVector(vector<T>& v, int mode) {
      |                  ~~~~~~~~~~~^
a.cc:230:36: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
  230 |         printVector(tree.getInOrder(), 0);
      |                     ~~~~~~~~~~~~~~~^~
a.cc:202:29: note:   initializing argument 1 of 'void printVector(std::vector<_Tp>&, int) [with T = int]'
  202 | void printVector(vector<T>& v, int mode) {
      |                  ~~~~~~~~~~~^
a.cc:232:38: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
  232 |         printVector(tree.getPostOrder(), 0);
      |                     ~~~~~~~~~~~~~~~~~^~
a.cc:202:29: note:   initializing argument 1 of 'void printVector(std::vector<_Tp>&, int) [with T = int]'
  202 | void printVector(vector<T>& v, int mode) {
      |                  ~~~~~~~~~~~^