标签:[] i++ typedef lse 遍历 type argv def null
还没有完善。。。
#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
typedef struct BaseNode* tree;
struct BaseNode {
BaseNode* left;
BaseNode* right;
int val;
BaseNode() {};
BaseNode(int v) : val(v), left(nullptr), right(nullptr)
{
}
};
void insert(tree & root, int & v)
{
std::cin >> v;
if (v == 0)
root = nullptr;
else
{
root = new BaseNode(v);
insert(root->left, v);
insert(root->right, v);
}
}
void sequence(tree root)
{
std::queue<tree> nodes;
// std::vector<int> nums;
tree rptr = root;
nodes.push(rptr);
while (!nodes.empty())
{
rptr = nodes.front();
nodes.pop();
if (rptr)
{
std::cout << rptr->val << " ";
nodes.push(rptr->left);
nodes.push(rptr->right);
}
}
/*
for (int i = 0; i < int(log(nums.size() + 1)) + 1; i++)
{
for (int j = 0; j < nums.size() - i; j++)
std::cout << " ";
for (int j = i; j < int(pow(2, i)) + 1; j++)
std::cout << nums[j] << " ";
std::cout << std::endl;
}
*/
}
int _tmain(int argc, _TCHAR* argv[])
{
tree root;
int v;
insert(root, v);
sequence(root);
std::cin >> v;
return 0;
}
标签:[] i++ typedef lse 遍历 type argv def null
原文地址:https://www.cnblogs.com/darkchii/p/9001767.html