DUYỆT CÂY 3
DUYỆT CÂY 3
#include <bits/stdc++.h>
struct Node {
int data;
Node* trai;
Node* phai;
Node(int val) {
data = val;
};
Node* nut_cha;
else {
danhsach[u] = nut_cha;
danhsach[v] = nut_con;
}
// Ham duyet BFS (level-order traversal)
if (!goc) return;
queue<Node*> q;
q.push(goc);
while (!q.empty()) {
if (hien_tai->trai) q.push(hien_tai->trai);
if (hien_tai->phai) q.push(hien_tai->phai);
int main() {
while (T--) {
int u, v; char x;
chen(goc, u, v, x, danhsach);
duyet_BFS(goc);
return 0; }
#include<vector>
#include<iomanip>
#include<algorithm>
#include<string.h>
#include<string>
#include<climits>
#include<set>
#include<map>
#include<stack>
#include<queue>
struct node {
int data;
node* pLeft;
node* pRight;
node(int x) {
this->data = x;
};
if (T == NULL) {
T = new node(u);
if (c == 'L')T->pLeft = p;
else T->pRight = p;
else {
if (T->data == u) {
if (c == 'L')T->pLeft = p;
else T->pRight = p;
else {
void Load(tree T) {
if (T == NULL)return;
S1.push(T);
while (S1.size()) {
S1.pop();
if (tmp->pRight != NULL)S2.push(tmp->pRight);
if (tmp->pLeft != NULL)S2.push(tmp->pLeft);
while (S2.size()) {
S2.pop();
if (tmp->pLeft != NULL)S1.push(tmp->pLeft);
if (tmp->pRight != NULL)S1.push(tmp->pRight);
int main(){
faster();
run() {
int n; cin >> n;
tree T = NULL;
FOR(i, 0, n) {
int u, v; char c;
Add(T, u, v, c);
Load(T);
Sinh Hoán vị
#include <iostream>
#include <vector>
#include <algorithm>
void sinh_hoan_vi(int N) {
vector<int> a(N);
a[i] = i + 1;
do {
}
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
sinh_hoan_vi(N);
return 0;